bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.56k stars 329 forks source link

need to replace a string using modify-overwrite-beta, REPLACE ABC string from attributes #1264

Closed naveenpi closed 4 months ago

naveenpi commented 4 months ago

i have following input:

{ "attributes": { "ABC_BCKHL": "123", "ABC_DHBLD": "234", "ABC_KKCAJ": "345", } }

EXPECTED OUTPUT: { "attributes": { "BCKHL": "123", "DHBLD": "234", "KKCAJ": "345", } }

Please give the solution using modify-overwrite-beta operation

naveenpi commented 4 months ago

i tried something like this but did not work

[{

"operation": "modify-overwrite-beta", "spec": { "attributes": { "*": "=substring(@(1,&),5,10)" } } }]

LucaBiscotti commented 4 months ago

Hi @naveenpi, the jolt you made is almost right, there are just some little improvements to do for make it work:

So the correct jolt should be something like this:

[
  {
    "operation": "shift",
    "spec": {
      "attributes": {
        "*": {
          "$": "@0"
        }
      }
    }
},
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=substring(@0,4,9)"
    }
},
  {
    "operation": "shift",
    "spec": {
      "*": {
        "$": "attributes.@0"
      }
    }
}
]
  1. exchange the key and the value
  2. apply the substring to the value(the original key)
  3. exchange again

Hope I helped

naveenpi commented 4 months ago

thank you it worked