My Input request payload is as below:
{
"attributes": {
"training": {
"attr1": "somevalue",
"attr2": "somevalue"
},
"services": [
{
"recommendedService": "medical",
"providedOrInitiated": 1
},
{
"recommendedService": "engineering",
"providedOrInitiated": 0
}
]
}
}
My desired output payload should be like:
{
"attributes": {
"training": { // Transform node if received in request
"training1": "somevalue",
"training2": "somevalue"
},
"services": { // Transform node if received in request
"medicalProvided": 1,
"engineeringProvided": 0,
"caProvided": 0, // If not received in request, set to 0 for all missing keys
"doctorProvided": 0,
"teacherProvided": 0
}
}
}
Here is my json transformation spec:
[
{
"operation": "shift",
"spec": {
"attributes": {
"ParentID": "customAttributesMap.ParentID",
"training": {
"attr1": "attributes.training.training1",
"attr2": "attributes.training.training2"
},
"services": {
"*": {
"recommendedService": {
"medical": {
"@(2,providedOrInitiated)": "attributes.services.medicalProvided"
},
"engineering": {
"@(2,providedOrInitiated)": "attributes.services.engineeringProvided"
}
// How to set default for missing input fields.
}
}
}
}
}
}
]
I tried with default operation, but it adds keys even if services node is not received in request. That should not happen. Requirement is like transform node whichever is present in request. And only that should be sent in output. That’s why default operation is not useful here.
Overall requirement is like Inside "service" node
{
"recommendedService": "<SERVICE_NAME>",
"providedOrInitiated": 1 // value 1 or 0
}
e.g. "medical" service is present then map medicalProvided to beneath providedOrInitiated value otherwise set it as 0.
All the nodes are dynamic. They might present or not.
2
Answers
You can use this spec:
You can consecutively use shift and modify transformations such as