0

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

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

5 Comments

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.
Sorry, not sure I follow. Would you mind providing a full example result you expect for the given input?
I have updated the output.
Right, I get it now - check this one out: stedi.link/ZBoBY2F
Thanks. I got one more question here to clear out my doubt. stackoverflow.com/questions/73882914/…

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.