skip to Main Content

Input JSON value :

 {
  "age": [
    {
      "r": "r1",
      "d": "{}"
    }
  ]
}

Desired Output :

{
  "age": [
    {
      "r": "r1",
      "d": {}
    }
  ]
}

I tried using modify-overwrite-beta but unable to replace string by empty dictionary.

2

Answers


  1. You can use the following shift transformation spec in order to convert {} to null, and then modify transformation spec along with notNull function to return the desired result such as

    [
      {
        "operation": "shift",
        "spec": {
          "age": {
            "*": {
              "*": {
                "*": { "@1": "&4[&3].&2" },
                "{}": "&3[&2].&1"
              }
            }
          }
        }
      },
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "age": {
            "*": {
              "*": ["=notNull", {}]
            }
          }
        }
      }
    ]
    

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

    enter image description here

    Login or Signup to reply.
  2. You can use this spec:

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "*": {
              "*": "&2.[&1].&",
              "d": {
                "{}": "&3.[&2].&1.temp"
              }
            }
          }
        }
      },
      {
        "operation": "remove",
        "spec": {
          "age": {
            "*": {
              "d": {
                "*": ""
              }
            }
          }
        }
      }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search