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

如何用jq将JSON参数文件解析为分号分隔的字符串

用jq解析JSON为指定键值对格式

输入JSON

[
  {
    "ParameterKey": "code",
    "ParameterValue": "ab"
  },
  {
    "ParameterKey": "env",
    "ParameterValue": "prod"
  },
  {
    "ParameterKey": "api",
    "ParameterValue": "testapi"
  },
  {
    "ParameterKey": "name",
    "ParameterValue": "new"
  }
]

解决命令

直接使用以下jq命令即可得到目标格式输出:

jq -r 'map("\(.ParameterKey)=\(.ParameterValue)") | join(";")' input.json

命令解释

  • map("\(.ParameterKey)=\(.ParameterValue)"):遍历数组中的每个对象,将每个对象的ParameterKey和ParameterValue拼接成key=value格式的字符串,最终生成一个字符串数组。
  • join(";"):将上述字符串数组用分号;连接成单个完整字符串。
  • -r:指定jq输出原始字符串(不带JSON格式的引号),确保输出符合需求。

执行结果

运行命令后会输出:

code=ab;env=prod;api=testapi;name=new

内容的提问来源于stack exchange,提问作者user24285544

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 00:07:03