I want to transform a given JSON structure into another json format using the JSONATA API. Basically, I need to break the hierarchical structure into separate records.
Input JSON:
{
"2022年09月22日": [
{
"name": "modules/dynatrace",
"count": 60
},
{
"name": "modules/dynatrace/monitors/http-monitors/basic",
"count": 4
},
{
"name": "modules/splunk/hec-token",
"count": 14
},
{
"name": "modules/aws/lambda/logs_streaming_splunk",
"count": 29
}
]
}
Output:
[
{
"date" : "2022年09月22日",
"name": "modules/dynatrace",
"count": 60
},
{
"date" : "2022年09月22日",
"name": "modules/dynatrace/monitors/http-monitors/basic",
"count": 4
},
{
"date" : "2022年09月22日",
"name": "modules/splunk/hec-token",
"count": 14
},
{
"date" : "2022年09月22日",
"name": "modules/aws/lambda/logs_streaming_splunk",
"count": 29
}
]
asked Sep 28, 2022 at 13:06
Ashish Sharma
6801 gold badge11 silver badges26 bronze badges
1 Answer 1
You can use the $each function to convert object into an array:
$each($,ドル function($entries, $date) {
$entries.($merge([{ "date": $date }, $]))
})
Interactive link: https://stedi.link/ZBoBY2F
answered Sep 28, 2022 at 13:28
mralex
1,1201 gold badge7 silver badges8 bronze badges
Sign up to request clarification or add additional context in comments.
5 Comments
Ashish Sharma
Thanks for your answer. I am here trying to prepare list of objects for each object located in the deep like 'name' and 'count'. So for given input it should return 8 objects.
mralex
Sorry, not sure I follow. Would you mind providing a full example result you expect for the given input?
Ashish Sharma
I have updated the output.
mralex
Right, I get it now - check this one out: stedi.link/ZBoBY2F
Ashish Sharma
Thanks. I got one more question here to clear out my doubt. stackoverflow.com/questions/73882914/…
default