bazaarvoice / jolt

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

JOLT: Split a number and replace a part of it with some string. #839

Open prakharchhipa opened 5 years ago

prakharchhipa commented 5 years ago

Having a number in input JSON(refer AON in given example), needs to split it half of the size and replace the second part with PP. For example: AON is 4323 in input, output should be like 43PP.

JSON Input:

{
  "DOCUMENT": {
    "SAMPLE": {
      "TRANSACTION": {
        "ITEMIZED": [
          {
            "TYPES": [
              {
                "ROW": [
                  {
                    "Amount": "0.00",
                    "Time": "18:28:24",
                    "Date": "21/MAY/2019"
                  },
                  {
                    "AON": 2451,
                    "Amount": "0.00",
                    "Time": "20:48:20",
                    "Date": "22/MAY/2019"
                  },
                  {
                    "AON": 4513,
                    "Amount": "0.00",
                    "Time": "17:02:39",
                    "Date": "27/MAY/2019"
                  }
                ]
              }
            ]
          }
        ]
      }
    }
  }
}

Transformation:(I've tried to do, but this is the question)

[
  {
    "operation": "shift",
    "spec": {
      "*": "&"
    }
  },
  {
    "operation": "remove",
    "spec": {
      "DOCUMENT": {
        "SAMPLE": {
          "TRANSACTION": {
            "ITEMIZED": {
              "*": {
                "TYPES": {
                  "*": {
                    "ROW": {
                      "*": {
                        "Number":""
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

Desired output JSON:

{
  "DOCUMENT": {
    "SAMPLE": {
      "TRANSACTION": {
        "ITEMIZED": [
          {
            "TYPES": [
              {
                "ROW": [
                  {
                    "Amount": "0.00",
                    "Time": "18:28:24",
                    "Date": "21/MAY/2019"
                  },
                  {
                    "AON": "24PP",
                    "Amount": "0.00",
                    "Time": "20:48:20",
                    "Date": "22/MAY/2019"
                  },
                  {
                    "AON": "45PP",
                    "Amount": "0.00",
                    "Time": "17:02:39",
                    "Date": "27/MAY/2019"
                  }
                ]
              }
            ]
          }
        ]
      }
    }
  }
}
prakharchhipa commented 5 years ago

I'm using version:0.1.0 of com.bazaarvoice.jolt