Xojo.Data.GenerateJSON restriction?

I have a Xojo.Core.dictionary. One of the entries has a value of type currency. If I try to convert the dictionary to text with Xojo.Data.GenerateJSON I get a xojo.Core.InvalidArgumentException.

According the docs there should be no exception. Or am I wrong?

I’ve gotten that too. Meant to file a Feedback report about it but never did. You should though because that should work as if it were a double.

Well, it shouldn’t putting it into JSON as a Double. Converting to a Double loses the precision guarantee that Currency has.

So this is expected behavior?


Expected behaviour that a dictionary entry with a currency value cannot be converted to text with Xojo.Data.GenerateJSON? That’s against the docs.

JSON doesn’t really have a type that can round trip as a “currency”
You could maybe put one in but it would have to be written as a floating point value (double)
On the way out you would not be able to get it as a currency - json has no notion of “currency”

Currencies to doubles?? Floating points are not precise.
Better handle them as cents (or whatever precision you want) and use Int’s.

I’ve run something similar, too. See <https://xojo.com/issue/38580> 38580 - JsonException when converting a json to string that comes from a dictionary with a date. Makes the JsonItem.ToString method not very useful.

JSON strings can only hold Strings, Numbers, Booleans, NULLs and other JSON objects. If you need dates, you must store them as a string or a number.