JMESPath - 连接嵌套数组中的项目
JMESPath - Joining items in a nested array
我有一个JSON
{
"key": "processId-29231",
"fields": {
"attachment": [
{
"id": "79572",
"filename": "File1.png"
},
{
"id": "74620",
"filename": "File2.docx"
},
{
"id": "79072",
"filename": "File3.xlsx"
}
]
}
}
我需要将其重组为这个
{
"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",
]
}
我可以使用特定的数组索引来完成这项工作
{processID:key,attachments:join('',['https://example.com/files/',fields.attachment[1].id,'/',fields.attachment[1].filename])}
产生这个结果
{
"processID": "processId-29231",
"attachments": "https://example.com/files/74620/File2.docx"
}
我尝试了两种没有数组索引的方法
这个
{processID:key,attachments:join('',['https://example.com/',fields.attachment[].id,'/',fields.attachment[].filename])}
还有这个
{processID:key,attachments:join('', ['https://example.com/',fields.attachment[*].id,'/',fields.attachment[*].filename])}
但这并没有帮助。
关于如何解决这个问题的任何提示?
您需要将函数应用于数组的每个元素并通过@
访问当前节点
{processID:key,attachments: fields.attachment[].join('',['https://example.com/files/', @.id, '/', @.filename])}
我有一个JSON
{
"key": "processId-29231",
"fields": {
"attachment": [
{
"id": "79572",
"filename": "File1.png"
},
{
"id": "74620",
"filename": "File2.docx"
},
{
"id": "79072",
"filename": "File3.xlsx"
}
]
}
}
我需要将其重组为这个
{
"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",
]
}
我可以使用特定的数组索引来完成这项工作
{processID:key,attachments:join('',['https://example.com/files/',fields.attachment[1].id,'/',fields.attachment[1].filename])}
产生这个结果
{
"processID": "processId-29231",
"attachments": "https://example.com/files/74620/File2.docx"
}
我尝试了两种没有数组索引的方法
这个
{processID:key,attachments:join('',['https://example.com/',fields.attachment[].id,'/',fields.attachment[].filename])}
还有这个
{processID:key,attachments:join('', ['https://example.com/',fields.attachment[*].id,'/',fields.attachment[*].filename])}
但这并没有帮助。
关于如何解决这个问题的任何提示?
您需要将函数应用于数组的每个元素并通过@
{processID:key,attachments: fields.attachment[].join('',['https://example.com/files/', @.id, '/', @.filename])}