bazaarvoice / jolt

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

Substring on Array of String using modify-overwrite/default-beta #1189

Open dbug-river opened 1 year ago

dbug-river commented 1 year ago

Hi, would it be possible to highlight why split on a string of array works while substring does not? Example

input

{
    "input":
    [
        "a:c",
        "a:d"
    ]
}

spec

[
    {
        "operation": "modify-default-beta",
        "spec":
        {
            "input_split": "=split(':',@(2,input))",
            "input_substring": "=substring(@(2,input),1,2)"
        }
    }
]

output

{
  "input" : [ "a:c", "a:d" ],
  "input_split" : [ [ "a", "c" ], [ "a", "d" ] ]
}

I'm expecting the output to have input_substring containing ["a", "a"].

Your help will be greatly appreciated and thanks in advance

gawhadebhavna commented 1 year ago

Hi @dbug-river

If you are expecting the output is like below

{
  "input" : [ "a:c", "a:d" ],
  "input_substring" : [ "a", "a" ]
}

You can use the below spec

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "input_split": "=split(':',@(2,input))"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "input_split": {
        "*": {
          "0": "input_substring"
        }
      }
    }
  }
]