You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用JQ借助JSON中compare列表提取对应results值?

JQ 匹配提取指定键的结果

针对你提供的JSON结构,这里有几种实用的JQ命令可以满足需求:

1. 提取键值对数组

把compare列表中的每个编码和results里对应的值配对输出:

.query.compare[] as $code | {code: $code, value: .results[$code]}

执行结果:

{"code":"10006","value":0.54}
{"code":"10007","value":0.93}

2. 分别提取两个独立列表

  • 提取compare列表的编码:

    .query.compare
    

    输出:

    ["10006","10007"]
    
  • 提取对应results的值列表:

    .query.compare[] | .results[.]
    

    输出:

    0.54
    0.93
    

3. 生成关联对象

直接生成以compare编码为键、对应结果为值的对象:

.reduce .query.compare[] as $key ({}; .[$key] = .results[$key])

执行结果:

{"10006":0.54,"10007":0.93}

内容的提问来源于stack exchange,提问作者Ayman.1302

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 18:58:15