I want to extract all fields from a JSON array and turn it into a flat JSON file. Here is an example of the input:
Array JSON input:
{
"field1": "ALNT12345",
"field2": "ALNT345346",
"field3": "2015353423",
"field4": "2332124343",
"arrayfield1": [
{
"arr1": "625347",
"arr2": "rere"
},
{
"arr1": "634441",
"arr2": "sdfsd"
}
]
}
The goal is to convert the above array JSON into 2 separate records like this, using JSON path:
Required Output:
[
{
"field1": "ALNT12345",
"field2": "ALNT345346",
"field3": "2015353423",
"field4": "2332124343",
"arr1": "625347",
"arr2": "rere"
},
{
"field1": "ALNT12345",
"field2": "ALNT345346",
"field3": "2015353423",
"field4": "2332124343",
"arr1": "634441",
"arr2": "sdfsd"
}
]
In my attempt with JSON path,
$.arrayfield1.*
It only retrieves array fields. If JSON path doesn't work for this, can you recommend a JavaScript code to retrieve all the fields?
Thanks.