JMESPath-在嵌套数组中连接项目 [英] JMESPath - Joining items in a nested array
本文介绍了JMESPath-在嵌套数组中连接项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个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",
]
}
我可以使用特定的数组索引
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])}
产生此结果
{
"processID": "processId-29231",
"attachments": "https://example.com/files/74620/File2.docx"
}
我以两种方式尝试了不使用数组索引的情况
I tried this without array index in two ways
此
{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])}
但这没有帮助.
有关如何解决此问题的任何提示?
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
这篇关于JMESPath-在嵌套数组中连接项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文