Store Dynamic JSON in mendix and display in a page grid

Hi,   I have a JSON string in this format [{“Record ID”:”0”, “Student details”:[ { “Student Name” : ”Amrish Kumar”, “Student Age”: “36”, “Student Class” : “8th”}, { “Student Name” : ”Anil Kumar”, “Student Age”: “38”, “Student Class” : “12th”, “Student Subject” : ”English” }, { “Student Name” : ”Ajit Kumar”, “Student Class” : “11th”, “Student Subject” : ”Hindi” }] and the resultant table which needs to be created in mendix doesn’t  have fixed attributes its attributes are dynamic based on the student details JSON string from the above . the resultant table based on above data is shown below:-   so the records whose value is not present in the key value pair must be set to empty and table headers are also dynamically created.     Edit: This is just a sample response, one json object can have more than 20 + attributes and there can be different objects types (student or class or object 1 , object 2 etc) we don't want to limit to an import mapping to defined structure , but scalable so that we should be able to accept more dynamic attributes.   The best approach we are thinking is to create generic key values pair to store, however again we need to display these in table with search feature. For example, now one record is like combination of key values pairs, we need to display these keys as headers and values from key value pairs as separate column in a row. (Nested list with each row is a nested list of key value).       Thanks in advance. Regards Amrish Kumar  
2 answers

You can just use the correct JSON snippet and use it in an Import Mapping.

If some attributes are empty, that should be no problem.



In the JSON snippet you showed, you are missing the last line (with the closing brackets). This is the correct and valid JSON

	"Record ID": "0",

	"Student details": [{

			"Student Name": "Amrish Kumar",

			"Student Age": "36",

			"Student Class": "8th"


			"Student Name": "Anil Kumar",

			"Student Age": "38",

			"Student Class": "12th",

			"Student Subject": "English"



			"Student Name": "Ajit Kumar",

			"Student Class": "11th",

			"Student Subject": "Hindi"




Hi Amrish,


I had a similar problem. I hope it will be solution if you can use below two methods for dynamic json value.

I will present two methods. I used the first. I even used the answers from the forum for this but I can't remember which one at the moment.

1- Finding a solution by writing code in Java and keeping it as a Dictionary<key, value> pair: Not configuring the fields at all is not suitable for business logic. In this case, I assume you will want to display them on the screen. You can write a json map java action for this that creates a list of Mendix objects with 2 attributes like "key" and "value".

2- If there is a certain number of fields shown you can create a generic json snippet with all possible fields and Mendix will only map existing fields to an object. Or like the answers above, in case these fields are empty, you can check the default values and write them to the db.


I hope that helps in your project.