bazaarvoice / jolt

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

inquiry on conditional statements - 2 or more object validation at the same time #1248

Closed mordfustang00 closed 2 months ago

mordfustang00 commented 3 months ago

hello. i would like to ask a question.

Below is my json input:

{ "carValidation": { "pressureValue": { "type": 0, "unit": 1 or 0, "value": "00H" } } } }

where type value refers to some old or new values on a reference table unit, refers to 0 - Celcius or 1 - Fahrenheit, and value refers to hex value.

i think this is a complicated one, but what i want to achieve is like this:

if unit = 0 convert 0 to 5 If type = 0 convert value from hex to numeric (based on a table list = e.g. if 00H = 0 C) if unit = 1 convert 0 to 4 If type = 0 convert value from hex to numeric (based on a table list = e.g. if 00H = 32 F) end-if

thanks.

mordfustang00 commented 3 months ago

I try the spec below:

//sample json - airtemp conv [ { "operation": "shift", "spec": { "carValidation": { "": "carValidation.&", "pressureValue": { "": "carValidation.pressureValue.&", "unit": { "0": { "#5": "carValidation.pressureValue.unit", "type": { "0": { "value": { "00H": { "#0": "carValidation.pressureValue.value" } } } } }, "1": { "#4": "carValidation.pressureValue.unit" } } } } } }, { "operation": "modify-overwrite-beta", "spec": { "carValidation": { "pressureValue": { "unit": "=toInteger" } } } }, { "operation": "shift", "spec": { "carValidation": { "": "carValidation.&", "pressureValue": { "": "carValidation.pressureValue.&" } } } }

]

only giving me the following output:

{ "carValidation" : { "pressureValue" : { "type" : 0, "unit" : 5, "value" : "00H" } } }

mordfustang00 commented 2 months ago

closing. already made a workaround on this.