skip to Main Content

I need help to remove null elements from JSON using jolt. I want to remove only root level elements containing null.

Input :

{
  "x": null,
  "y": null,
  "z": [
    {
      "id": "1",
      "name": "2",
      "price": null,
      "quantity": 1
    }
  ]
}

Expected Output

{
  "z": [
    {
      "id": "1",
      "name": "2",
      "price": null,
      "quantity": 1
    }
  ]
}

2

Answers


  1. Just dive one level deeper while using basic "*": "&" match in order the attributes stated at the outermost level with null values to vanish such as

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "*": "&1[]" // &1 represents the key grabbed from one outer level(it's "z" here)
          }
        }
      }
    ]
    

    the demo on the site http://jolt-demo.appspot.com/ is

    enter image description here

    Login or Signup to reply.
  2. You can use the value of the z and bring in the z like this:

    [
      {
        "operation": "shift",
        "spec": {
          "@z": "z"
        }
      }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search