Reputation: 121
Having considered the following input :
{
"MainObj": {
"SubObj": {
"Name": "John",
"Surname": "Smith",
"Items": [
{
"ItemDetails": {
"MissingKey1": "MissingValue1" //this is working in spec
}
},
{
"ItemDetails": [
{
"MissingKey1": "MissingValue2" //this is not working
},
{
"MissingKey2": "Not available" //this is not working
}
]
}
]
}
}
}
related to this question i have another scenario in which i am trying to add "MissingKey2" inside an ItemDetails array. ItemDetails can be an object or can be an array. I was able to add "MissingKey2" inside the object of ItemDetails, but not able to in case of ItemDetails is an array. The spec i am using:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"MainObj": {
"SubObj": {
"Items": {
"*": {
"ItemDetails": {
"~MissingKey1": "Not available", //this is working
"*": {
"~MissingKey2": "Not available" //this is NOT working
}
}
}
}
}
}
}
}
]
Upvotes: 1
Views: 26
Reputation: 65408
The conditional logic doesn't operate in a complete manner in a modify transformation spec that operates in a shift spec. Thus, you could apply them within individual specs one by one as like in the following transformation :
[
{
"operation": "modify-overwrite-beta",
"spec": {
"MainObj": {
"SubObj": {
"Items": {
"*": {
"ItemDetails": {
"*": {
"~MissingKey3": "Not available"
}
}
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"MainObj": {
"SubObj": {
"Items": {
"*": {
"ItemDetails": {
"~MissingKey3": "Not available"
}
}
}
}
}
}
}
]
which is assumed to add a new attribute MissingKey3
to both object and array structure.
Upvotes: 1