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

如何使用jq工具获取/更新数组中notebook_task的base_parameters值

使用jq获取和更新JSON中指定字段的值

目标JSON结构片段:

"settings": {
   "tasks": [
      {
        "email_notifications": {},
        "job_cluster_key":"artifactory_download_job_cluster",
        "max_retries":0,
        "min_retry_interval_millis":900000,
        "notebook_task": {
          "base_parameters": {
            "project":"app1",
            "path":"dir1/source1/file"
          }
        }
      }
    ]
}

一、获取project和path的值

  • 获取所有tasks中的project值:
    jq -r '.settings.tasks[].notebook_task.base_parameters.project' your_file.json
    
  • 获取所有tasks中的path值:
    jq -r '.settings.tasks[].notebook_task.base_parameters.path' your_file.json
    
  • 同时获取两个字段(以结构化形式输出):
    jq '.settings.tasks[].notebook_task.base_parameters | {project, path}' your_file.json
    

二、更新project和path的值

更新单个字段

  • 将project更新为app2:
    jq '.settings.tasks[].notebook_task.base_parameters.project = "app2"' your_file.json > updated_file.json
    
  • 将path更新为dir2/source2/new_file:
    jq '.settings.tasks[].notebook_task.base_parameters.path = "dir2/source2/new_file"' your_file.json > updated_file.json
    

同时更新两个字段

如果需要一次操作更新两个字段,且保留base_parameters中的其他字段(如有):

jq '.settings.tasks[].notebook_task.base_parameters += {project: "app2", path: "dir2/source2/new_file"}' your_file.json > updated_file.json

如果要完全替换base_parameters为仅包含这两个字段的对象:

jq '.settings.tasks[].notebook_task.base_parameters = {project: "app2", path: "dir2/source2/new_file"}' your_file.json > updated_file.json

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 20:16:07