How to separate string from an object in native

0
I am getting an object having number of attributes. How to separate the attributes. Please help.   eg:- {     "string": {         "content":"[{\"DepartmentNameAR\":\"القسم الطبي\",\"DepartmentNameEN\":\"Medical Department\",\"SectionNameAR\":\"العلاج الطبيعي\",\"SectionNameEN\":\"Physiotherapy\"}]",         "xmlns": "http://tempuri.org/"     } } Note:- Using 8.5 mendix version Smita
asked
1 answers
0

The json you receive contains more json in the array.

What you could do is:

  1. create a json structure
  2. create a microflow with that calls the rest service
  3. use the structure to map the data into an object via a mapping
  4. the content attribute of the mapping will contain the second part of your json data like this
[{\"DepartmentNameAR\":\"القسم الطبي\",\"DepartmentNameEN\":\"Medical Department\",\"SectionNameAR\":\"العلاج الطبيعي\",\"SectionNameEN\":\"Physiotherapy\"}]
  1. change the content field of the imported object with 2 actions
  2. action 1 is a change object with the following change to the content : replaceAll($FirstImport/Content, '/','') removing the escape chars
  3. action 2 is a change object with the following change to the content:substring($FirstImport/Content, 1, length($FirstImport/Content)-1) this gets rid of the extra [] chars
  4. Create a second json structure using the value above without the / and [] chars
  5. add a new action in the microflow to create a string variable
  6. add a new action in the microflow to import json with a new mapping created based on the second json structure

Now you have the different fields from the original array in an object.

Below are some screenshots of the json structures, mappings and microflow to better understand the actions above:

json struct 1:

mapping 1:

json struct 2:

 

microflow (the first part is a string representing the response from the rest call as a string and the import, this you’ll not need as you’ll import the data directly from the rest call)

Hope this give you some ideas on how to proceed.

answered