json 当值等于某个值时抖动删除对象

svujldwt  于 2023-06-07  发布在  其他
关注(0)|答案(2)|浏览(156)

我有一个这样的输入-

[
  {
    "time": "2014-10-31T01:59:59.000+10:00",
    "value": {
      "nil": null
    },
    "metadata": {
      "TVPMeasurementMetadata": {
        "qualifier": {
          "title": null,
          "href": null
        }
      }
    },
    "longitude": "115.1248985",
    "latitude": "-33.963617",
    "gathered_time": "1685662804091"
  },
  {
    "time": "2014-11-30T02:00:00.000+10:00",
    "value": {
      "nil": null
    },
    "metadata": {
      "TVPMeasurementMetadata": {
        "qualifier": {
          "title": null,
          "href": null
        }
      }
    },
    "longitude": "115.1248985",
    "latitude": "-33.963617",
    "gathered_time": "1685662804091"
  },
  {
    "time": "2014-12-10T02:00:00.000+10:00",
    "value": 83.939,
    "metadata": null,
    "longitude": "115.1248985",
    "latitude": "-33.963617",
    "gathered_time": "1685662804091"
  },
  {
    "time": "2014-12-11T02:00:00.000+10:00",
    "value": 84.089,
    "metadata": null,
    "longitude": "115.1248985",
    "latitude": "-33.963617",
    "gathered_time": "1685662804091"
  }
]

我想要的是只获取JSON对象中包含数值数据并且不等于{“nil”:null}...以下是预期的输出。

[
    {
      "time" : "2014-12-10T02:00:00.000+10:00",
      "value" : 83.939,
      "metadata" : null,
      "longitude" : "115.1248985",
      "latitude" : "-33.963617",
      "gathered_time" : "1685662804091"
    }, {
      "time" : "2014-12-11T02:00:00.000+10:00",
      "value" : 84.089,
      "metadata" : null,
      "longitude" : "115.1248985",
      "latitude" : "-33.963617",
      "gathered_time" : "1685662804091"
    }
]

我尝试了几个不同的规格操作,如删除,但这些都没有得到我的任何地方。

vmpqdwk3

vmpqdwk31#

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "value": {
          "nil": {
            "null": {
              "": ""
            }
          },
          "*": {
            "@2": ""
          }
        }
      }
    }
  }
]
ffvjumwh

ffvjumwh2#

这是您的Jolt规格:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "value_temp": "@(1,value)",
        "value_tem*": ["=toInteger", "null"]
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "value_temp": {
          "*": {
            "@2": "data.&1"
          }
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "data": {
        "null": "",
        "*": {
          "value_temp": ""
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": "[#2].&"
        }
      }
    }
  }
]

相关问题