gpt4 book ai didi

json - Xidel json xpath - 如何获取多个元素的值

转载 作者:行者123 更新时间:2023-12-05 05:26:30 27 4
gpt4 key购买 nike

需要使用 Xidel 从 json 数据中获取多个元素值。单元素查询,如:

xidel - -e 'jn:members(json($raw))("client_name")'

xidel - -e 'jn:members(json($raw))("amount")'

工作正常但谷歌搜索了很长时间,无法找到如何构造多元素提取的表达式。以下尝试失败:

xidel - -e 'jn:members(json($raw))("client_name","amount")'
xidel - -e 'jn:members(json($raw))("client_name,amount")'
xidel - -e 'jn:members(json($raw))("client_name")("amount")'
xidel - -e 'jn:members(json($raw))[("client_name")("amount")]'

最佳答案

一些 Xidel 特定的东西(>=0.8 版本):

  1. 您不再需要 json($raw)$json 就足够了

  2. 它有自己的 JSON 读取语法,比 JSONiq 更像 XPath:

    xidel - -e 'jn:members($json) / (client_name, amount)'

    或如其他评论中所问:

    xidel - -e 'string-join($json / (id, your_name, total), ",")'

而在普通的 JSONiq 中,可以使用库函数:

  declare namespace libjn= "http://jsoniq.org/function-library"; 
string-join(libjn:values(libjn:project($json, ("id", "your_name", "total"))), ",")

关于json - Xidel json xpath - 如何获取多个元素的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25470100/

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