I have a JSON
{
"key": "processId-29231",
"fields": {
"attachment": [
{
"id": "79572",
"filename": "File1.png"
},
{
"id": "74620",
"filename": "File2.docx"
},
{
"id": "79072",
"filename": "File3.xlsx"
}
]
}
}
I need to restructure it to this
{
"processId": "processId-29231",
"attachments": [
"https://example.com/files/79572/File1.png",
"https://example.com/files/79572/File2.docx",
"https://example.com/files/79572/File1.xlsx",
]
}
I could make this work with a specific array index
{processID:key,attachments:join('',['https://example.com/files/',fields.attachment[1].id,'/',fields.attachment[1].filename])}
which yields this result
{
"processID": "processId-29231",
"attachments": "https://example.com/files/74620/File2.docx"
}
I tried this without array index in two ways
this
{processID:key,attachments:join('',['https://example.com/',fields.attachment[].id,'/',fields.attachment[].filename])}
and this
{processID:key,attachments:join('', ['https://example.com/',fields.attachment[*].id,'/',fields.attachment[*].filename])}
but that did not help.
Any tips on how this can be solved?
You need to apply the function to each element of the array and access the current node via @
{processID:key,attachments: fields.attachment[].join('',['https://example.com/files/', @.id, '/', @.filename])}
http://jmespath.org/specification.html#functions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With