Critical gap in API & JSON

I’ll be seeking a few testers for a pure Xojo configuration I’ve written that, so far, handles everything I’ve thrown at it AND includes a machoism for USERS to be able to custom format ANY value they want

Its for CREATING JSON only at this point (parsing is far too slow in pure Xojo code)

Let me know if you’re interested

the example given in the bug reported on that case

Dim j As New JSONItem
j.DecimalFormat = "-0.0##"
j.Value("4") = 12345.67891
MsgBox j.ToString

turns into

Dim j As New GWSJSONItem

Dim m As New MyCustomJsonValue
m.value = 12345.67891
m.decimalformat = "-0.0##"

j.Value("4") = m
MsgBox j.ToString

and yields


Another example (just so you can see it handles the formatting right)

  Dim j As New GWSJSONItem
  Dim m As New MyCustomJsonValue
  m.value = -54321.0987654321
  m.decimalformat = "-0.0##"
  j.Value("5") = m
MsgBox j.ToString



Isn’t this handled by plugins?

I dont think any handle currency or custom formatting of double values which is the issue

At least in my quick research it wasnt - which made me tinker with this

EDIT : Oh and you wont get source code for those plugins to tinker with if you so desire

I expect to make this available in source form as well eventually

1 Like

A post was split to a new topic: JSON In Other Languages

There is also this: GitHub - ktekinay/JSONItem_MTC: A drop-in, faster replacement for the native Xojo JSONItem class
that offers DecimalFormat. I think it was faster than old JSONItem but slower than the new one that Xojo offers.

Looks like .DecimalFormat is deprecated in Xojo:

No, but thank you.
I don’t think I need yet another JSON Library for Xojo.

We’re happy with the MBS one. Einhugur also has JSON Plugins. And such as Alberto mentioned, there is Kem’s JSONItem_MTC.

I just stumbled upon this “deprecation”, which somehow is a “regression” (or a “bug”, since old/existing code now produces an unexpected output) as this has taken away a useful feature that once existed.

It’s just sad to say: you (currently) can’t reliably produce a JSON with (decimal) number values with “pure Xojo”.

1 Like

You can - just not using Xojo’s implementations :stuck_out_tongue:


Yeah I think the old one was Xojo code

And the new one based the code in the Xojo framework using GenerateJSON so its underpinnings are all in C++
And it DIDNT honour the DecimalFormat that I recall
Nor support Currency - not sure why though

Mines not intended to be a drop in replacement
its mean to be even more “natural”

So to set an items with a key and an array of values you can just do

   dim j as new GWSJsonItem
   j.add("key") = array("123", "456")

and this would create

{ "key" : [ "123", "456"] }

And some other shortcuts like arrays of classes as long as they implement a really simple interface

EDIT : for instance to serialize a bunch of settings from a class (in this case from my CONSOLE test app) to JSON
I can do the following

  1. implement the ICustomJsonValue interface in my App class (just for fun) as follows
Dim g As New GWSJSONItem

Dim g2 As New GWSJSONItem
g2.value("MajorVersion") = Self.MajorVersion
g.append g2

g2 = New GWSJSONItem
g2.value("MinorVersion") = Self.MinorVersion
g.append g2

g2 = New GWSJSONItem
g2.value("BugVersion") = Self.BugVersion
g.append g2

g2 = New GWSJSONItem
g2.value("NonReleaseVersion") = Self.NonReleaseVersion
g.append g2

g2 = New GWSJSONItem
g2.value("Copyright") = Self.Copyright
g.append g2

g2 = New GWSJSONItem
g2.value("ExecutableFile.NativePath") = Self.ExecutableFile.NativePath
g.append g2

g2 = New GWSJSONItem
g2.value("ShortVersion") = Self.ShortVersion
g.append g2

g2 = New GWSJSONItem
g2.value("StageCode") = Self.StageCode
g.append g2

g2 = New GWSJSONItem
g2.value("Version") = Self.Version
g.append g2

Return g.ToString

this code will return an array of JSON items each with a name & value

  1. code the following
Dim g As New GWS.GWSJSONItem

g.Value("App") = App // yes I can put the App in the JSON

Print g.tostring

Dim j As Variant = ParseJSON(g.tostring) // test it generated proper JSON

and that Print statement prints out

{"App":[{"MajorVersion":1},{"MinorVersion":0},{"BugVersion":0},{"NonReleaseVersion":0},{"Copyright":""},{"ExecutableFile.NativePath":"\/Users\/npalardy\/Great White Software\/RB Test Projects\/My Application.debug\/My Application.debug"},{"ShortVersion":""},{"StageCode":0},{"Version":""}]}