Home > Mobile >  Jolt transform specification input
Jolt transform specification input

Time:05-13

i have the following input json:

{
  "tags": {
    "event": "observation",
    "source": "hunter"
  }
}

The output JSON should look like below:

{
  "tags" : [ "event:observation", "source:hunter" ]
}

can anyone provide any guidance on how to build a proper jolt specification for the above?

thank you very much for the help ^_^

CodePudding user response:

You can use this specification

[
  { // combine each key-value pair under within common arrays
    "operation": "shift",
    "spec": {
      "tags": {
        "*": {
          "$": "&2_&1",
          "@": "&2_&1"
        }
      }
    }
  },
  { // concatenate key-value pairs by colon characters 
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=join(':',@(1,&))"
    }
  },
  {
    "operation": "shift",
    "spec": { // make array key common("tags") for all arrays 
              // through use of _ seperator and * wildcard 
      "*_*": "&(0,1)"
    }
  }
]

the demo on the site enter image description here

  • Related