JSON Dynamic Structure

Hello All, is there a way to create JSON structure dynamically, for example i have list of objects with structure {id, name, surname} and i want json to be like – {    “id”: {           “0”: “2343”,           “1”: “4343”    },    “name”: {              “0”: “Martin”,              “1”: “Frank”     },    “surname”: {            “0”: “Brown”,            “1”: “Striker”    } }   Is there any possibility to make such JSON?
1 answers

Hi Vadim,

In Mendix, a list is always considered to be of the same type. That doens't mean that all attributes/associations of each object must be filled. I can create a list like above by creating two entities, having 3 associations in between: id, name and surname. The first entity without any other attributes and the second entity having 1 and 2 as attribute names.

In the first set of objects I create, I only set the id association, the second only the name association and the third only the surname association.

So, if the set of options is not too big, you could model this completely in Mendix. But to have the “surname” a variable name in your JSON, that is not possible using the Mendix native export to JSON functionality. In that case, you should consider custom Java actions.

Hopefully this helps!

Kind regards,