Is there a way in mendix where I can convert a string to a Object

0
I have a String data as a response, but I need an object which is present inside that string to display that data. I’m unable to do any string manupulation in mendix, is there any way to extract that object from the string data . For example   "data":"{\"CompanyId\":105,\"CompanyName\":\"THE BRITISH SULPHUR CORP. LTD.\"}" Thanks in advance  
asked
3 answers
0

I think you’re going to need to do some string manipulation at some point.

One approach would be to pass the original string through an import mapping, you should be able to get the data attribute as a string then. You could then unescape this string using string manipulation before passing into another import mapping to get the data into an entity.

Good luck!

answered
0

Hi Harshitha,

  There is a way to import strings directly into objects using Import Mappings.

  You can take your string and pass it into a ‘Import Mapping’ microflow action as outlined here.

  The one catch that Robert P. mentions is that your data needs to be in a specific format. You need a consistent JSON structure for each type of object you want to extract. If you have the EXACT string you mention above, you have some extra carriage returns \ stuck in there. You might need to use a microflow to change the string. This can be done using the ‘Change Variable’ microflow object. The specific command to remove those would use the replaceAll function:

replaceAll($String,'\','')

If you are curious about how to do microflows with strings, then check out our free online training courses.

 

 

 

answered
0

Hi Harshita,

                  In Mendix, we can able to convert the JSON string into Mendix supportable Objects using Import mapping process.  For that, we need to create  JSON Structure. JSON Structure is act like template, it will help us to create the Mendix Objects. Then we need to add this JSON_Structure inside the import mapping activity. It will return the Root Object, We can get Data object from by association retrieve. That Data object will contain Company ID and Company Name attribute. I hope it will help you. I will give some ideas to remove the backslashes from the string using String functions in Mendix with your example, it will return the JSON formatted string.  For detailed explanation, I will share some screenshots. If this solves your problem, you can make my answer as Accepted. 

Thanks and Regards,

Vijayabharathi.

 

Step 1:  Create a JSON Structure first.  If you right click on the module. You can see the Add other option in which you can create JSON structure. 

 

 

Step 2: We need to give the proper JSON structured String inside the curly braces ({}) like this.

 

 

Step 3:  Create Import mapping and add the JSON structure. Then select Map automatically which is in top of the navigation to import the Mendix Supportable Objects Structure.

 

Step 4: Create one microflow with import mapping. Inside the Import mapping activity, select the latesthttpResponse as a input variable. Add your import mapping and Object name.

 

Step 5: Using by association retrieve you can get your Data Object.

 

 

To get the JSON formatted string dynamically using microflow :

 

answered