这是我输入的JSON:
{
"AddressBilling": {
"FirstName": "Some Name",
"LastName": "Some Name",
"Address":"some address"
}
"AddressShipping": {
"FirstName": "",
"LastName": "",
"Address":""
}
}
我想保留“AddressBilling”和“AddressShipping”,但使用不同的名称i:e“payment_address”和“shipping_address”,我已经为payment_address“part
写了一个spec文件{
"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"
}
}
}
现在我想要检查“AddressShipping”对象中的“Address”键是否为null然后我想将“AddressBilling”的“Address”复制到“shipping_address”的“Address”。
答案 0 :(得分:4)
可以使用“modify-default”执行此操作。如果密钥不存在或者其值为空,则Modify-default将仅填充值。
规格
[
{
"operation": "modify-default-beta",
"spec": {
"shipping_address": {
"address": "@(2,payment_address.address)"
}
}
}
]
输入A,其中没有送货地址
{
"payment_address": {
"address": "some address"
},
"shipping_address": {}
}
生成输出A,其中帐单地址通过
复制{
"payment_address" : {
"address" : "some address"
},
"shipping_address" : {
"address" : "some address"
}
}
输入B,其中有shipping_address
{
"payment_address": {
"address": "some address"
},
"shipping_address": {
"address": 1234
}
}
生成输出B,其中送货地址不会被覆盖。
{
"payment_address" : {
"address" : "some address"
},
"shipping_address" : {
"address" : 1234
}
}