How to display nested Json objects in each row?

How to display nested Json objects in each row?

thangnvthangnv Posts: 12Questions: 2Answers: 0
edited March 2021 in Free community support

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

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    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

  • montoyammontoyam Posts: 568Questions: 136Answers: 5

    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 :)

  • thangnvthangnv Posts: 12Questions: 2Answers: 0

    @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.

This discussion has been closed.