skip to Main Content

I have the following example of JSON and there many other fields apart from these 3

[
  {
    "field1": "xyz",
    "field2": "mno",
    "res1": "pqrs"
  },
  {
    "field1": "xyz1",
    "field2": "mno1",
    "res1": "pqrs1"
    
  }..other entries
]

I would like to empty the contents of field res1.

I tried this

[
  {
    "operation": "default",
    "spec": {
      "*": {
        "*": {
          "res": ""
        }
      }
    }
  }
]

but it does not work. Please help in this case.

I use this site to test my Jolt Spec

2

Answers


  1. Hi this spec will help you do it :

    If you want to empty res1 field as "res1": "".
    try this spec:

    [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": {
            "res1": ""
          }
        }
      }
    ]
    

    If you want to remove res1 field as entirely.
    try this spec:

       [
          {
            "operation": "remove",
            "spec": {
              "*": {
                "res1": ""
              }
            }
          }
        ]
    
    Login or Signup to reply.
  2. Hi if you want to add a condition for res1 based on field1 field try this spec:

    This means if field1 is either "/folder1/subfolder/name" or "/folder2/subfolder/name" or "/folder3/subfolder/name" then res1 value stay as it is else it will be removed.

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "field1": {
              "/folder1/subfolder/name|/folder2/subfolder/name|/folder3/subfolder/name": {
                "@(2,field1)": "[#4].field1",
                "@(2,field2)": "[#4].field2",
                "@(2,res1)": "[#4].res1"
              },
              "*": {
                "@(2,field1)": "[#4].field1",
                "@(2,field2)": "[#4].field2"
              }
            }
          }
        }
      }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search