gpt4 book ai didi

JMESPath - 加入嵌套数组中的项目

转载 作者:行者123 更新时间:2023-12-03 21:23:32 24 4
gpt4 key购买 nike

我有一个 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])}

http://jmespath.org/specification.html#functions

关于JMESPath - 加入嵌套数组中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50595005/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com