Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Jolt remove nested dict

I have the following input json (simplified; the real one has more keys):

{
    "key1":{
        "null":null
    },
    "key2":123
}

and I’d like like to simplify the null dict into a simple null like this:

{
    "key1": null,
    "key2":123
}

My latest attempt is the following jolt:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "null": "&1",
        "@": "&"
      }
    }
   }
]

But this results in:

{
  "key1": [
    {
      "null": null
    },
    null
  ],
  "key2": 123
}

because the second rule is matcing again key1 and appending again the orignal value to the same position.

Does anybody know how to do this?
Thanks in advance

>Solution :

You might use the conditional "null" vs. otehrs("*") nested within the object such as

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "null": "&1",
        "*": {
          "@1": "&2" // bring the value from 2 upper level,
          // where @ matches the 1st, @1 matches the 2nd level's value
          // while &2 replicates the key from 2 upper level  
        } 
      }
    }
  }
]

the demo on the site https://jolt-demo.appspot.com/#inception is :

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading