解析对象以删除条目

时间:2014-08-26 23:49:28

标签: json parsing object

我将如何解析此对象,删除所有条目" field" =" status",但同时保留JSON对象的有效性(即同时删除无关的对象)关闭对象末尾的括号或括号?

{"逻辑":"和""过滤器":[{"过滤器":[{"场&# 34;:"名称""操作":"含有""值":" JOHNSON"},{ "字段":"城市""操作":"含有""值":"密尔沃基& #34;}],"逻辑":"和"},{"逻辑":"或""过滤器&# 34;:[{"字段":"状态""操作":"当量""值&#34 ;: " A"},{"字段":"状态""操作":"当量"&#34 ;值":" G"},{"字段":"状态""操作":"当量&# 34;,"值":" O"},{"字段":"状态""操作&#34 ;: "当量""值":" P"},{"字段":"状态"&#34 ;操作":"当量""值":" S"}]}]

1 个答案:

答案 0 :(得分:0)

以下是使用jq基于my answersimilar question

的解决方案
filter.jq

如果data.json包含此过滤器且$ jq -M -f filter.jq data.json 包含示例数据,则命令

{
  "logic": "and",
  "filters": [
    {
      "filters": [
        {
          "field": "name",
          "operator": "contains",
          "value": "JOHNSON"
        },
        {
          "field": "city",
          "operator": "contains",
          "value": "MILWAUKEE"
        }
      ],
      "logic": "and"
    },
    {
      "logic": "or",
      "filters": []
    }
  ]
}

产生

node('buildprod_iamsg'){

              echo "\u001B[34mSending status to dynamodb pib-deployments ...\u001B[0m"
              checkout scm
              def dynamo = load "aws/dynamo.groovy"
              dynamo.add_metadata(substring, stripped_env, "down", lz, slackChannelName, slackToken, awsAccount, stack, ldapCommaSepList, githuburl, approver_name, time)
              echo "\u001B[34mJob status sent to dynamodb pib-deployments\u001B[0m"
}