简体   繁体   中英

JOLT Transformation - Remove leading zeros from String

I have a example input:

{
  "number": "0000000000068908"
}

or an other example input:

{
  "number": "0012000000034458"
}

Is it possible to remove the leading zeros from string via jolt transformation to get the following output?

{
  "number": "68908"
}

or

{
  "number": "12000000034458"
}

sorry for the late reply,there are several ways to reach that, one I can imagine is turn the string into a numeric value(eg a long int) after this, the zeros to the left will be removed, and then you can use that result and convert it to string again.

here you can play:

http://jolt-demo.appspot.com/#modify-typeConversion

and here the demo: json:

{
  "number": "0000000000068908"
}

Jolt Spec:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "number": "=toLong"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "number": "=toString"
    }
  }
]

result:

{
  "number" : "68908"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM