Stringify to JSON with toString($Variable) & use also as input for JSON structure - Mendix Forum

Stringify to JSON with toString($Variable) & use also as input for JSON structure

2

Hi guys

As you may know there is an easy function for creating JSON objects in Javascript, namely : JSON.stringify(JSONObject).

The way in Mendix seems a little unpractical to me, you have to create each time a JSON structure (you have to write JSON self or create self anyway) and then an import/export mapping and have to use the import/export mapping in your mf.

I think that it would be lot lot easier for developers to have a stringify function to make JSON objects by simply toString($Variable) default function, which also could be used as input function for a JSON structure.

asked
2 answers

1) Why?
You can map full objects in loggins as string

 

2)How?
Like in JS, just stringify the object, not the associations. I think JS work also so.

 

3) Best way?
Especially to specify an object as JSON, definitely not the best way. For REST services may be...but creating a JSON structure and mapping to get a JSON of an object seems unrapid and unpractical to me.

Created

Interesting idea! If the resulting JSON is obvious, why would you need to create it?

But how would it work? Objects have associations, which have associations, etc. These can even be cyclic. Would it put all of these associations in the string?

Currently the best way of turning an object into JSON is with a message definition. In the message definition you select which associations you want to include.

Created