skip to Main Content

I have an input like this –

[
  {
    "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"
  }
]

What I want is to only get values the JSON objects that have numerical data in them and don’t equal {"nil": null} … Here’s what the expected output looks like.

[
    {
      "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"
    }
]

I tried a couple different specs operations like remove but those didn’t get me anywhere.

2

Answers


  1. This is your Jolt spec:

    [
      {
        "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].&"
            }
          }
        }
      }
    ]
    
    Login or Signup to reply.
  2. [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "value": {
              "nil": {
                "null": {
                  "": ""
                }
              },
              "*": {
                "@2": ""
              }
            }
          }
        }
      }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search