How to display nested Json objects in each row?
How to display nested Json objects in each row?
thangnv
Posts: 12Questions: 2Answers: 0
Hi, I have a Json data as following
[{
"dad": "David",
"mom" : "Linda",
"children" : [{ "1": "Tony", "2":"Elsa"}]
},
{
"dad": "Tom",
"mom" : "Rebecca",
"children" : null
}]
And I'd like to display on DataTables:
Dad Mom Children
---------------------------------------------
David Linda Tony
David Linda Elsa
Tom Rebecca (empty)
Could you please give me an example for above output?
Thanks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You would need to convert that array into a new array with the format that you want, based on the number of children in the object.
Colin
or you could use a parent/child setup like this:
https://datatables.net/blog/2019-01-11
funny...parent/child for your parent/child data
@colin Thank for your suggestion. I also thought about flattening the JSON child array.
@montoyam In my real-life scenario, I have to display children in the same row with parents. Thanks for the link though. It's very good reference.