0
votes

I want to transform below input json to output json using JOLT. The main problem here is in the list, I have to remove some fields whose root key (Param1, Param2, ...) will differ dynamically. I tried below spec, which didn't work. Need help in this case.

Input JSON : [
  {
    "paramCollection": [
      {
        "Param1": {
          "value": 1,
          "limit": "10"
        }
      },
      {
        "Param2": {
          "value": 1,
          "limit": "20"
        }
      }
    ]
  }
]

Output JSON : [ {
  "paramCollection" : [ {
    "Param1" : {
      "value" : 1
    }
  }, {
    "Param2" : {
      "value" : 1
    }
  } ]
} ]

spec : [
  {
    "operation": "remove",
    "spec": {
      "*": {
        "paramCollection" : {
          "*": {
            "[&1].[&1].limit": ""
          }
        }
      }
    }
  }
]
1

1 Answers

1
votes

You are almost correct. This is the slightly modified spec which should work:

[
  {
    "operation": "remove",
    "spec": {
      "*": {
        "paramCollection": {
          "*": {
            "*": {
              "limit": ""
            }
          }
        }
      }
    }
  }
]

The [&1].[&1]. seems reduntant and incorrect. It seems that the remove operation does not support the apmersand (&) wildcard. See the shift operation docs

'&' Wildcard

  • Valid on the LHS (left hand side - input JSON keys) and RHS (output data path)