I'm new to JSONATA, so this is probably a pretty easy formatting problem that I don't know yet. I need to take a large object and reduce it down into something more manageable. I've been able to do this with objects, but am running into a problem with a particular data structure. It's metadata from a list of images, where the keywords are in an array of objects each with the structure {"name": "keyword"}. Like this:
{
"body": {
"files": [
{
"id": 101936854,
"title": "Taco Salad",
"keywords": [
{
"name": "background"
},
{
"name": "baked"
},
{
"name": "beef"
}
]
},
{
"id": 412961542,
"title": "Fiji",
"keywords": [
{
"name": "beach"
},
{
"name": "sea"
},
{
"name": "tree"
}
]
}
]
}
}
When I use the query
$zip(body.files.id,body.files.title,body.files.[keywords.name])
{
"id": $[0],
"title": $[1],
"keywords": $[2]
}
I get what I want, but only the first object, like so:
{
"id": 101936854,
"title": "Taco Salad",
"keywords": [
"background",
"baked",
"beef"
]
}
If I add the . to output all the objects, I get back multiple objects but only the first value of name in the array. Like so:
$zip(body.files.id,body.files.title,body.files.[keywords.name]).
{
"id": $[0],
"title": $[1],
"keywords": $[2]
}
Gets:
[
{
"id": 101936854,
"title": "Taco Salad",
"keywords": "background"
},
{
"id": 412961542,
"title": "Fiji",
"keywords": "beach"
}
]
I believe this is because the input objects in that array all have the same key of name. So, I need to somehow get all the values of name and put them in one array called keywords.