I have this case where if defaultshipping is true, the phone should be placed into shippingAddressBook->phone (same for billing). My transformation is close but the issue is that it is not grabbing the value of "phone".
Can someone help me with this please :)
Input:
{
"phone": "869-947-4444",
"defaultshipping": false,
"defaultbilling": true
}
Expected Output:
{
"billingAddressBook" : {
"phone" : "869-947-4444"
}
}
My transformation attempt:
[
{
"operation": "shift",
"spec": {
"defaultbilling": {
"true": {
"#phone": "billingAddressBook.phone"
}
},
"defaultshipping": {
"true": {
"#phone": "shippingAddressBook.phone"
}
}
}
}
]
CodePudding user response:
Yes, you're so close, just need to go 2 level up in order to reach the level of phone
and grab the value through use of @(2,phone)
such as
[
{
"operation": "shift",
"spec": {
"defaultbilling": {
"true": {
"@(2,phone)": "billingAddressBook.phone"
}
},
"defaultshipping": {
"true": {
"@(2,phone)": "shippingAddressBook.phone"
}
}
}
}
]