I have data in JSON format:
{
"orders":[
{
"id":"1",
"price":720,
"customers":[
{
"id":"10",
"name":"customer A"
},
{
"id":"14",
"name": "customer B"
}
]
},
{
"id":"2",
"price":68,
"customers":[
{
"id":"7",
"name":"customer X"
},
{
"id":"8",
"name":"customer Y"
}
]
}
]
}
My task is go throught these data and create table with columns like for example orders.id
, orders.number
, orders.customers.id
and so on (and of course with data from right side) and with all permutations for nested objects.
So in this case I should got something like:
+-----------+--------------+---------------------+-----------------------+
| orders.id | orders.price | orders.customers.id | orders.customers.name |
+-----------+--------------+---------------------+-----------------------+
| 1 | 720 | 10 | customer A |
| 1 | 720 | 14 | customer B |
| 2 | 68 | 7 | customer X |
| 2 | 68 | 8 | customer Y |
+-----------+--------------+---------------------+-----------------------+
The main problem is that I don't know the structure of this file when loading it. So I don't know the type, name and number of attributes and nesting level. I don't know what classes I should keep data in.
I tried use this: https://stackoverflow.com/a/58009049/11846473 to flatten my Json, but I'm not sure if this is good idea...
I would like use Jaskson library to do this. Could you give me some hints?