cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Dynamic output

nitishjain
Deputy Chef I
Deputy Chef I

Hi

I have a scenario where I'm using a parse Json and output structure is dynamic. here id and ans can be of any number or there'll be no id.

how can I add the data in the list?

example:

[
    {
        "employeeId": "010",
        "id_1": "001",
        "ans_1": "001",
        "id_2": "002",
        "ans_2": "002",
        "id_3": "003",
        "ans_3": "003"
    },
    {
        "employeeId": "020",
        "id_1": "001",
        "ans_1": "001"
    },
    {
        "employeeId": "030"
    }
]
3 REPLIES 3

gary1
Executive Chef III
Executive Chef III

Manually construct a fully-declared example and use that example in the parser. Like this:

//actual data with multiple objects
[
 {"a": 1},
 {"b": 2},
 {"c": 3}
]

//fully-declared single object for parser
[
 {
  "a": 1,
  "b": 2,
  "c": 3
 }
]

If the keys themselves are dynamic and you don't know what they'll be, then you'll have to take a different and more complicated approach.

nitishjain
Deputy Chef I
Deputy Chef I

data I provided is just an example but in actual/sandbox/prod scenario it can be any number. so I want to understand the  different and more complicated approach.
Thanks

Hi @nitishjain,

I have implemented a Python solution to structure the data effectively by differentiating employeeId and organizing ID-Ans pairs into a structured sublist. The output follows this format:

{
    "employeeId": "010",
    "subList": [
        {
            "id": "001",
            "ans": "001"
        },
        {
            "id": "002",
            "ans": "002"
        },
        {
            "id": "003",
            "ans": "003"
        }
    ]
}

This structured approach ensures that each employee's data is efficiently stored in a list. I'm successfully appending it to a master list without any issues. 

Final output looks:

{
	"message": [
		{
			"EmployeeList": [
				{
					"employeeId": "010"
				}
			],
			"subList": [
				{
					"id": "001",
					"ans": "001"
				},
				{
					"id": "002",
					"ans": "002"
				},
				{
					"id": "003",
					"ans": "003"
				}
			]
		},
		{
			"EmployeeList": [
				{
					"employeeId": "020"
				}
			],
			"subList": [
				{
					"id": "001",
					"ans": "001"
				}
			]
		},
		{
			"EmployeeList": [
				{
					"employeeId": "030"
				}
			],
			"subList": []
		}
	]
}

 main logic.PNG

Please let me know if you need further assistance.

Thanks and Regards,
Shivakumar K A