Currency in JSONItem

Hello XOJO community,

our company created a little framework serializing XOJO objects from a specific base class to Json objects by using XOJOs introspection framework. Basically what it does - it fills a JSONItem by looking into the classes structure. The performance isn’t an issue for our use case.

This works, more or less, smoothly.

Unfortunately, due to a very bad design choice of an API we have to connect to, we are forced to express money values as JSON numbers. So its our task to create JSON objects like this (mind the vat, incl_vat, excl_vat properties)

{ "type": "Auszahlung", "name": "Auslagen", "purchaser_agency_id": 1, "amounts_per_vat_id": [ { "id": 5, "incl_vat": 10.00, "excl_vat": 10.00, "vat": 0.00 } ], "custom_fields": { "custom_bc": "Wert des Custom-Feldes" } }

Internally in our classes, we represent those properties in question with the currency type. Here, the problem emerges: JSONItem can’t deal with the Currency type.

Basically, I think we need to create our own version of “JSONItem” to “teach” it, how to handle currency instances.

Do you have a better idea?



Use my JSONItem_MTC drop-in replacement.

Also, FYI:

Thank you Kem.

I wil try it out asap. I guess this will solve my problem!

Hey again.

Actually, your code was a great suggestion and it works now. But there are several suggestions of mine:

  1. There are 7 test failures. I’m not sure why they are but I guess it would be great to fix them.
  2. I used the normal JSONItem before - so many of other XOJO users will. For interface reasons, I would suggest that JSONItem_MTC should extend from JSONItem, even if this is not really a good usage of inheritance. But otherwise users of JSONItem have to change many of their lines of code for the type definition. I even started that in my fork, but It is not finished for all JSONItem functions yet:
  3. @Kem Tekinay are you interested in integrating my change in 2) into your project in github? If so, we could try adding some tests and fixing the current test failures in 1). There is the problem with the xojo_code_xml format for the JSONITem_MTC file as it’s not able to track the changes when you save in XOJO (at least for me).
    I’m looking forward to make JSON great again (for XOJO) and help to improve your great work!



  1. The only failures I’m aware of are the ones that test the native JSONItem, and are meant to show the limitations of that class, and let us know when or if they are fixed. Are you seeing others?

  2. Yes, it seems I could have done that. At the time I thought I’d be shadowing properties that should not be shadowed, but a quick test shows that I can probably eliminate those properties. I’ll consider that for some future version, but the issue hasn’t really come up. (Keep in mind that this class is many years old now.)

Switching your project over to my class is just a matter of doing a find/replace of JSONItem -> JSONItem_MTC. There shouldn’t be any other code changes.

Moving forward, I’d expect people to use the new ParseJSON and GenerateJSON native methods as they are significantly faster.

You’re welcome to do a pull request against my develop branch and I’ll consider your changes.