JMESPath - 连接嵌套数组中的项目

2024-03-20

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

我在没有数组索引的情况下尝试了两种方法

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])}

但这没有帮助。

关于如何解决这个问题有什么建议吗?


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

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JMESPath - 连接嵌套数组中的项目 的相关文章

  • 如何将JSON数据保存在本地(本机上)?

    我使用以下链接创建树状结构 这是我的代码
  • 删除零线二维numpy数组

    I run a qr factorization in numpy它返回一个列表ndarrays 即Qand R gt gt gt q r np linalg qr np array 1 0 0 0 1 1 1 1 1 reshape 3
  • 如何重定向到 CloudFront 分配中的特定 CNAME

    我在 AWS 中有 2 个 CloudFront 发行版 每个发行版都有自己不同的证书 每个 CNAME 都附加了多个 CNAME 并且每个 CNAME 在 Route 53 中都有一个对应的记录集 有没有办法将其中一个 URL 重定向到另
  • 在 C++ 中使用 setInterval()

    在JavaScript中 有一个函数叫做setInterval 用C 可以实现吗 如果使用循环 程序不会继续 而是继续调用该函数 while true Sleep 1000 func cout lt lt Never printed 没有内
  • For循环应该打印出ArrayList属性和其他ArrayList属性

    我正在尝试从同一系统中的两个不同的 ArrayList 打印属性 无法让它工作并自杀找出为什么它不起作用 for int i 0 i lt resultlist size i Athlete matched null Result res
  • 通过 Google Apps 脚本发布 Google 电子表格

    是否可以使用 Google Apps 脚本将 Google 电子表格发布到网络上 现在我必须使用手动执行此操作File gt Publish to the web 我检查了所有 Google Apps 脚本参考和指南 但没有看到任何有关通过
  • Java Swing 元素转换

    我正在尝试制作一个小型的非商业应用程序 并使其具有设计良好的界面 具有屏幕转换等功能 我在一个 JFrame 中的单独面板上拥有每个 屏幕 并且希望能够在面板之间转换时平滑地滑动它们 有什么办法可以轻松地实现这一点吗 由于您尚未接受答案 我
  • jQuery 中 $.map 和 $.grep 有什么区别

    有什么区别 map and grep在 jQuery 中 我想要一个尽可能简单的答案 我假设你的意思是 grep and map 不同之处在于我们使用 grep在我们使用时过滤数组 map将函数应用于数组中的每个项目 这是一个比我能做出的更
  • PermissionError:[Errno 13] 权限被拒绝:pipenv 安装请求的“Pipfile”

    我正在尝试遵循有关 Pipenv 和 virtualenv 的指南 http docs python guide org en latest dev virtualenvs http docs python guide org en lat
  • 如何在iOS应用程序中解析JSON

    我从 Twitter 收到字符串形式的响应 我需要的是将注释所在的部分发送到数组 这是字符串的示例 geo null coordinates null retweeted false text KristinaKlp saluditos y

随机推荐