5

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

但这并没有帮助。

关于如何解决这个问题的任何提示?

4

1 回答 1

8

您需要将该函数应用于数组的每个元素并通过以下方式访问当前节点@

{processID:key,attachments: fields.attachment[].join('',['https://example.com/files/', @.id, '/', @.filename])}

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

于 2018-05-30T01:30:04.343 回答