REST --> Make list from object

0
Hi, an REST-API returns a single JSON-object with multiple attributes to a GET-request. How can I loop over the JSON within Mendix a in order to create a single object for each line of the JSON in my entity model? Thanks!   { "Afrikaans": "af", "Albanian": "sq", "Amhari": "am", "Arabi": "ar", "Armenian": "hy", "Azerbaijan": "az", "Bengal": "bn", "Bosnia": "bs", "Bulgarian": "bg", "Catala": "ca", "Chinese_Simplified": "zh", "Chinese_Traditional": "zh-TW", "Croatian": "hr", "Czech": "cs", "Danish": "da", "Dari": "fa-AF", "Dutch": "nl", "Englis": "en", "Estonian": "et", "Farsi_Persian": "fa", "Filipino,Tagalo": "tl", "Finnis": "fi", "French": "fr", "French_Canada": "fr-CA", "Georgian": "ka", "Germa": "de", "Greek": "el", "Gujarati": "gu", "HaitianCreol": "ht", "Hausa": "ha", "Hebrew": "he", "Hindi": "hi", "Hungarian": "hu", "Icelandic": "is", "Indonesian": "id", "Irish": "ga", "Italia": "it", "Japanese:": "ja", "Kannad": "kn", "Kazakh": "kk", "Korean": "ko", "Latvia": "lv", "Lithuanian": "lt", "Macedonian": "mk", "Malay": "ms", "Malayalam": "ml", "Maltes": "mt", "Marath": "mr", "Mongolian": "mn", "Norwegian": "no", "Pashto": "ps", "Polish": "pl", "Portuguese": "pt", "Portuguese_Portugal": "pt-PT", "Punjab": "pa", "Romanian:": "ro", "Russia": "ru", "Serbia": "sr", "Sinhal": "si", "Slovak": "sk", "Slovenian": "sl", "Somali": "so", "Spanis": "es", "Spanish_Mexico": "es-MX", "Swahil": "sw", "Swedis": "sv", "Tamil": "ta", "Telugu": "te", "Thai:": "th", "Turkis": "tr", "Ukrainian": "uk", "Urdu:": "ur", "Uzbek": "uz", "Vietnamese": "vi", "Welsh": "cy" }  
asked
2 answers
0

Hi Tjark,

if I got this right you receive one huge string attribute for that JSON object right?

You could use the “StringSplit” java function from the StringUtils in the CommunityCommons. Split it by the comma and then you can iterate over the resulting list to create a object for each.

Hope that helps!

 

Best regards

Jan

answered
0

Hi Tjark,

I think this would be a good application for a simple java action. You could use the copyattributes action from CommonityCommons as a source of inspiration for this.

Maybe going the MxModelReflection route could be an option, but i gove that a lower probability of success.

I hope this helps.

answered