4

I need to use jolt transform to do the below JSON transformation.

Need to split the "PID3" value in input Json to array of key value pairs in output Json

Input JSON

{ "PID1": "value1", "PID2": "value2", 
  "PID3": "k1^value1~k2^value2~k3^value3" # It is Dynamic might contain multiple key value pair seperated by ~ 
}

Output JSON

{
  "PID1": "value1",
  "PID2": "value2",
  "PID3": [
  {
  "key":"k1",
  "value":"value1"
  },
  {
  "key":"k2",
  "value":"value2"
  },
  {
  "key":"k3",
  "value":"value3"
  }

-- multiple based on the input string

  ]
}

1 Answer 1

4

This should do the trick:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "PID3": "=split('~', @(1,PID3))"
    }
    },
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "PID3": {
        "*": "PID3.[&].part"
      }
    }
    },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "PID3": {
        "*": {
          "part": "=split('\\^', @(1,part))",
          "key": "@(1,part[0])",
          "value": "@(1,part[1])"
        }
      }
    }
    },
  {
    "operation": "remove",
    "spec": {
      "PID3": {
        "*": {
          "part": ""
        }
      }
    }
    }
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.