bazaarvoice / jolt

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

Help with modifying a pattern of strings #1176

Open yq4103 opened 2 years ago

yq4103 commented 2 years ago

Can someone help me with the spec for this transformation? Thanks a lot. The length of the string may change, and the number of "." is also not fixed. After the jolt transform, I only want to keep the part of the string which comes after the last "." So I don't think substring is gonna work in this case.

JSON input: { "myString": "keep.only.the.last.word" }

Expected output: { "myString": "word" }

charlesardsilva commented 2 years ago

Hi, you can do this:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "myString": "=split('\\.',@(1,myString))"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "myString": "=lastElement(@(1,myString))"
    }
  }
]