bazaarvoice / jolt

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

Replacing empty string with null #1204

Open smillane opened 1 year ago

smillane commented 1 year ago

Input

[
    {
        // other data
        "employees": [{
            // other data
            "hireDate": ""
        }]
    }
]

I'm trying to set hireDate to null if its "" or " ", and keep all the other data in both objects.

I've tried variations such as

{
    "operation": "shift",
    "spec": {
        "*": {
            "*": "[&1].&",
            "employees": {
                "": null,
                " ": null,
                "*": {
                    "@": "&"
                },
            }
        }
    }
}

but everything I do leaves the employees array empty, when I want to retain each object with the same key/values, but just set hireDate to null if its an empty string.