0
votes

I have below user input json. [ { "correlationId": "12345", "payloadFormat": "Money", "payload": { "DE61": "000001000150084063368", "location": "south", "name": "Dallas", "pop": "2M" } }, { "correlationId": "ed1e3", "payloadFormat": "Cash", "payload": { "DE": "000001000150084063368", "location": "west", "name": "LosAngeles", "pop": "4M" } } ]

I need to convert in below output with the help of JOLT Spec

[ { "correlationId": "12345", "payloadFormat": "Money", "DE61SF1": "00", "DE61SF2": "100015008", "DE61SF3": "4063368", "location": "south", "name": "Dallas", "pop": "2M" }, { "correlationId": "ed1e3", "payloadFormat": "Cash", "DE61SF1": "00", "DE61SF2": "100015008", "DE61SF3": "4063368", "location": "west", "name": "LosAngeles", "pop": "4M" } ]

1

1 Answers

0
votes

Check this spec,

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@": "&",
        // Shift all the DE nodes to a same named node.
        // Here it is moved as TMPDE
        "payload": {
          "DE|DE61": "&2.payload.TMPDE"
        }
      }
    }
  }, {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "payload": {
          "DE61SF1": "=substring(@(1,TMPDE), 2, 4)",
          "DE61SF2": "=substring(@(1,TMPDE), 5, 14)",
          "DE61SF3": "=substring(@(1,TMPDE), 14, 21)"
        }
      }
    }
  }, {
    "operation": "shift",
    "spec": {
      "*": {
        "correlationId": "[&1].correlationId",
        "payloadFormat": "[&1].payloadFormat",
        "payload": {
          "DE61SF1": "[&2].DE61SF1",
          "DE61SF2": "[&2].DE61SF2",
          "DE61SF3": "[&2].DE61SF3",
          "location": "[&2].location",
          "pop": "[&2].pop",
          "name": "[&2].name"
        }
      }
    }
  }
]