Changing and Simplifying Result of DB2API Call
The default response of DB2API call is as below:
{
"statusCode" : 200,
"statusDescription" : "OK",
"columnNames" : [ "customerNumber", "customerName", "contactLastName", "contactFirstName", "phone", "addressLine1", "addressLine2", "city", "state", "postalCode", "country", "salesRepEmployeeNumber", "creditLimit" ],
"numRows" : 2,
"data" : [ {
"country" : "France",
"city" : "Nantes",
"contactFirstName" : "Carine ",
"postalCode" : "44000",
"salesRepEmployeeNumber" : 1370,
"customerNumber" : 103,
"customerName" : "Atelier graphique",
"phone" : "40.32.2555",
"addressLine1" : "54, rue Royale",
"creditLimit" : 21000.0,
"contactLastName" : "Schmitt",
"addressLine2" : null,
"state" : null
}, {
"country" : "France",
"city" : "Nantes",
"contactFirstName" : "Janine ",
"postalCode" : "44000",
"salesRepEmployeeNumber" : 1370,
"customerNumber" : 119,
"customerName" : "La Rochelle Gifts",
"phone" : "40.67.8555",
"addressLine1" : "67, rue des Cinquante Otages",
"creditLimit" : 118200.0,
"contactLastName" : "Labrune",
"addressLine2" : null,
"state" : null
} ],
"elapsedTime" : 11,
"errors" : [ ]
}
CODE
This JOLT example, renames the "data" element and clears it from other elements:
-------------------------------------------
JOLT
--------------------------------------------
[
{
"operation": "shift",
"spec": {
"data":"result"
}
}
]
--------------------------------------------
RESULT
--------------------------------------------
{
"result" : [ {
"country" : "France",
"city" : "Nantes",
"contactFirstName" : "Carine ",
"postalCode" : "44000",
"salesRepEmployeeNumber" : 1370,
"customerNumber" : 103,
"customerName" : "Atelier graphique",
"phone" : "40.32.2555",
"addressLine1" : "54, rue Royale",
"creditLimit" : 21000.0,
"contactLastName" : "Schmitt",
"addressLine2" : null,
"state" : null
}, {
"country" : "France",
"city" : "Nantes",
"contactFirstName" : "Janine ",
"postalCode" : "44000",
"salesRepEmployeeNumber" : 1370,
"customerNumber" : 119,
"customerName" : "La Rochelle Gifts",
"phone" : "40.67.8555",
"addressLine1" : "67, rue des Cinquante Otages",
"creditLimit" : 118200.0,
"contactLastName" : "Labrune",
"addressLine2" : null,
"state" : null
} ]
}
CODE
- This JOLT example shifts the "country" elements to the upper level and clears them from other elements:
-------------------------------------------
JOLT:
-------------------------------------------
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"country": "&"
}
}
}
}
]
--------------------------------------------
RESULT
--------------------------------------------
{
"country": [
"France",
"France"
]
}
CODE
- This JOLT example shifts the "country" elements' values to the upper level and clears them from other elements:
-------------------------------------------
JOLT:
-------------------------------------------
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"country": "[&1]."
}
}
}
}
]
--------------------------------------------
RESULT
--------------------------------------------
[
"France",
"France"
]
CODE