bazaarvoice / jolt

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

Convert boolean values to int #1237

Closed mordfustang00 closed 7 months ago

mordfustang00 commented 7 months ago

Good Day. Is there a way to convert boolean values to integer

My input would be:

{ "value": false or true }

My expected output should be:

{ "value": 0 or 1 }

I tried using "toInteger" code but only returns with boolean values (false, true)

gbouget commented 7 months ago

With shift + "true" or "false" correspondence. Second step is to tranform a string into an integer : =toInteger calls new com.bazaarvoice.jolt.modifier.function.Objects.toInteger() method in java.

[
  {
    "operation": "shift",
    "spec": {
      "value": {
        "true": {
          "#1": "booleanValueAsInteger" // or value or &2
        },
        "false": {
          "#0": "booleanValueAsInteger"
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "booleanValueAsInteger": "=toInteger"
    }
  }
]
mordfustang00 commented 7 months ago

many thanks :)