Hello all. I love your library, but I needed the ability to convert values as well as having a bit of conditional logic to decide whether values would be mapped based on the values of other values in the JSON document.
I put together a feature change that supports inline JSON Path Expressions for conditional branching and conversion of values, and would be curious if this would be something welcomed into the project?
Use case: let's say I had a JSON document with the following money value:
{ "annual_revenue": "$1,000,000" } and I wanted the output to be: {"agr":"1000000.00"} if the field existed, or {"agr":"0.00"} if it did not.
The above example could be achieved with:
{
"operation": "shift",
"converters": {
"regex": {
"remove_dollar_sign": {
"match": "\\$?\\s*(.*)",
"replace": "$1"
},
"remove_comma": {
"match": ",",
"replace": ""
}
}
},
"spec": {
"agr": "annual_revenue ? \"0.00\" | regex remove_dollar_sign | regex remove_comma | ston | format %.2f"
}
}
I've updated the documentation with syntax examples for all of the Converters that I added, and have the feature built out with tests in this same commit:
https://github.com/mbordner/kazaam/blob/feature/value-conditional-and-converter-expressions/README.md#json-path-parameters
https://github.com/mbordner/kazaam/blob/feature/value-conditional-and-converter-expressions/README.md#converter-specification-support
Another example: Say, I want to change the state name from Ohio to OH in the following document: {"state":"Ohio"} to produce: {"state":"OH"}
I could achieve this with:
{
"operation": "shift",
"converters": {
"mapped": {
"states": {
"Ohio": "OH",
"Texas": "TX"
}
}
},
"spec": {
"state": "state | mapped states"
}
}
or with
{
"operation": "shift",
"spec": {
"state": "state | upper | substr 0 2"
}
}
Hello all. I love your library, but I needed the ability to convert values as well as having a bit of conditional logic to decide whether values would be mapped based on the values of other values in the JSON document.
I put together a feature change that supports inline JSON Path Expressions for conditional branching and conversion of values, and would be curious if this would be something welcomed into the project?
Use case: let's say I had a JSON document with the following money value:
{ "annual_revenue": "$1,000,000" }and I wanted the output to be:{"agr":"1000000.00"}if the field existed, or{"agr":"0.00"}if it did not.The above example could be achieved with:
{ "operation": "shift", "converters": { "regex": { "remove_dollar_sign": { "match": "\\$?\\s*(.*)", "replace": "$1" }, "remove_comma": { "match": ",", "replace": "" } } }, "spec": { "agr": "annual_revenue ? \"0.00\" | regex remove_dollar_sign | regex remove_comma | ston | format %.2f" } }I've updated the documentation with syntax examples for all of the Converters that I added, and have the feature built out with tests in this same commit:
https://github.com/mbordner/kazaam/blob/feature/value-conditional-and-converter-expressions/README.md#json-path-parameters
https://github.com/mbordner/kazaam/blob/feature/value-conditional-and-converter-expressions/README.md#converter-specification-support
Another example: Say, I want to change the state name from Ohio to OH in the following document:
{"state":"Ohio"}to produce:{"state":"OH"}I could achieve this with:
{ "operation": "shift", "converters": { "mapped": { "states": { "Ohio": "OH", "Texas": "TX" } } }, "spec": { "state": "state | mapped states" } }or with
{ "operation": "shift", "spec": { "state": "state | upper | substr 0 2" } }