Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content
Announcements
Gartner® Magic Quadrant™: 15 YEARS A LEADER - GET THE REPORT
cancel
Showing results for 
Search instead for 
Did you mean: 
mattg1221
Contributor II
Contributor II

Recursive JSON Loop problem. Does the JSON Loop path only allow for loops on the same depth?

I am having an issue on how to iterate through a json file with a recursive field to populate a table. Let us say I have a json file of the structure as followed:
{
"firstName": "John",
"address" : "1 Main St",
"children" : [
{ "firstName" : "James",
"address": "3 Commercial St",
"children": [
{
"firstName": "Sara",
"address": "4 Hunt Drive"
},
{
"firstName": "Sam",
"address": "here3"
}

]
}
]
}
The json objects contain the fields "firstName", "address" and sometimes the list "children", which contains objects of the same schema, hence a recursive loop.

I wish to create a table that has "firstName" and "address" as columns and each row will correspond to one json object. Simply specifying the json query '$..firstName' for example enters all of the instances of 'firstName' as one row - I do not know how to get each as its own row, which requires a recursive json loop to all levels where children lists are present.

Labels (4)
3 Replies
Dave_Simo
Creator
Creator

Hello @mattg1221 

Can you give an example of what you want to have as a result from one of your json? This will allow me to know how to implement this recursive loop in question.

Best regards

mattg1221
Contributor II
Contributor II
Author

It would be a table with two columns like the following:

|firstName | Address|
John           1 main st

James        3 Comm St

Sara            4 Hunt Drive

 

Dave_Simo
Creator
Creator

Hello @mattg1221 


I found an algo (job design) below that will allow you to parse your json recursively.

Dave_Simo_0-1750099674516.png

1) 

Dave_Simo_1-1750099804327.png

 

2)

Dave_Simo_2-1750099883897.pngDave_Simo_3-1750099917579.png

3)

Dave_Simo_4-1750099953859.pngDave_Simo_5-1750099970843.png

4) 

Dave_Simo_7-1750100017396.png

5) 

Dave_Simo_8-1750100046948.png

 

Best Regards