问题
This is my input JSON:
{
"AddressBilling": {
"FirstName": "Some Name",
"LastName": "Some Name",
"Address":"some address"
}
"AddressShipping": {
"FirstName": "",
"LastName": "",
"Address":""
}
}
I want to keep "AddressBilling" and "AddressShipping" but with different names i:e "payment_address" and "shipping_address", for which i have written a spec file for payment_address" part
{
"operation": "shift",
"spec": {
"AddressBilling": {
"FirstName": "payment_address.firstname",
"LastName": "payment_address.lastname",
"Address": "payment_address.address"
},
"AddressShipping": {
"FirstName": "shipping_address.firstname",
"LastName": "shipping_address.lastname"
}
}
}
Now what I want is to check if "Address" key in "AddressShipping" object is null then i want to copy "Address" of "AddressBilling" to "Address" of "shipping_address".
回答1:
Can do that with "modify-default". Modify-default will only fill in a value if a key does not exist or it's value is null.
Spec
[
{
"operation": "modify-default-beta",
"spec": {
"shipping_address": {
"address": "@(2,payment_address.address)"
}
}
}
]
Input A, where there is not shipping address
{
"payment_address": {
"address": "some address"
},
"shipping_address": {}
}
Produces output A, where the billing address is copied over
{
"payment_address" : {
"address" : "some address"
},
"shipping_address" : {
"address" : "some address"
}
}
Input B, where there is a shipping_address
{
"payment_address": {
"address": "some address"
},
"shipping_address": {
"address": 1234
}
}
Produces output B, where the shipping address does not get overwritten.
{
"payment_address" : {
"address" : "some address"
},
"shipping_address" : {
"address" : 1234
}
}
来源:https://stackoverflow.com/questions/45411165/check-if-null-or-empty-in-jolt-and-put-another-value-which-is-present-in-input-j