I'm trying to flatten this json object with nested arrays into individual objects at the top level. It's a little weird because the array elements have different elements
{
"MyData": {
"identifier" : "abc",
"Query" : [
{
"Name" : "q1",
"Row" : [
{
"Name" : "John",
"Age" : "21"
},
{
"Name" : "Jane",
"Age" : "20"
}
]
},
{
"Name" : "q2",
"Row" : [
{
"Country" : "USA",
"Population" : "100"
},
{
"Country" : "Mexico",
"Population" : "99"
}
]
}
]
}
}
I'd like it to end up like this
{
"PersonRow" : {
"identifier" : "abc",
"Type" : "q1",
"Name" : "John",
"Age" : "21"
}
}
{
"PersonRow" : {
"identifier" : "abc",
"Type" : "q1",
"Name" : "Jane",
"Age" : "20"
}
}
{
"CountryRow" : {
"identifier" : "abc",
"Type" : "q2",
"Country" : "USA",
"Population" : "100"
}
}
{
"CountryRow" : {
"identifier" : "abc",
"Type" : "q2",
"Country" : "Mexico",
"Population" : "99"
}
}
Is it possible to flatten so all objects get to the top level? I'm guessing I have to do a ruby filter but not sure where to start.