0

I am trying to map one a value of input json to a hashmap of the output json and also want to save the value to some another key using jolt json transformation

input json:

{
  "metadata": "/a=value1/b=value2/c=value3"
}

spec:

 [{
            "operation": "shift",
            "spec": {
              "metadata": {
                // match exactly sets of key value pairs
                "/*/*/*": {
                  // pull each one off and accumulate them into a temp array
                  "$(0,1)": "temp[]",
                  "$(0,2)": "temp[]",
                  "$(0,3)": "temp[]"
                }
              }
            }
          },
          {
            "operation": "shift",
            "spec": {
              "temp": {
                "*": {
                  // match each item by ":" into two captures
                  "*=*": {
                    "$(0,2)": "data.&(1,1)"
                  }
                }
              }
            }
            }

        ]

output

 {
          "data" : {
            "a" : "value1",
            "b" : "value2",
            "c" : "value3"
          }
        }    

whereas I also want to map the string metadata to originalData Expected Output:

{
  "data" : {
    "a" : "value1",
    "b" : "value2",
    "c" : "value3"
  },
  "originalData":"/a=value1/b=value2/c=value3"
}
Pooja
  • 13
  • 4

2 Answers2

0

Spec

    [
      {
        "operation": "shift",
        "spec": {
          "metadata": {
            "@": "originalData",
            // match exactly sets of key value pairs
            "/*/*/*": {
              // pull each one off and accumulate them into a temp array
              "$(0,1)": "temp[]",
              "$(0,2)": "temp[]",
              "$(0,3)": "temp[]"
            }
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "originalData": "originalData", // passthru
          "temp": {
            "*": {
              // match each item by ":" into two captures
              "*=*": {
                "$(0,2)": "data.&(1,1)"
              }
            }
          }
        }
      }
    ]
Milo S
  • 4,466
  • 1
  • 19
  • 22
0
 [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "metadata": "=split('/',@(1,metadata))"
        }
      },
      {
        "operation": "shift",
        "spec": {
          "metadata": {
            "*": {
              "*=*": {
                "$(0,2)": "data.&(1,1)"
              }
            }
          }
        }
      }
     ]
Narsireddy
  • 368
  • 5
  • 10