This is a common issue when working with JSON in Mendix. So far my solution has been to change the json string to a format that can be parsed e.g.
{
"feedback":{
"code1":{
"request_duration":106175
},
"code2":{
"request_duration":106175
}
}
}
Should be converted to
{
"feedback":[
{
"key" : "code1",
"request_duration":106175
},
{
"key" : "code2",
"request_duration":106175
}
]
}
This can then be easily mapped. Depending on the JSON you can do the transformation with a string replace or in java by parsing the json and then restructuring it.
Hope this helps
EDIT:
Here is java code snippet to do the restructuring
JSONObject json = new JSONObject(json_string);
JSONObject feedback = json.getJSONObject("feedback");
JSONArray restructured_feedback = new JSONArray();
Iterator<String> iter = feedback.keys();
while ( iter.hasNext() ) {
String key = iter.next();
JSONObject o = feedback.getJSONObject(key);
o.put("key", key);
restructured_feedback.put(o);
}
json.put("feedback", restructured_feedback);
I’ve published a Mendix module with a similar approach to transform the JSON into an array
https://marketplace.mendix.com/link/component/212893