I want to modularize my data retrieval queries that generate json into service program procedures. However, I do not know how to get db2 to generate json value pairs without the object or array terminators ({} []). Here is what I mean by this.
Sample json result
I envision that I can create a srvpgm procedure to return customer info, ie. getCustomerInfoJson(customerNumber), and another procedure to return orders (ie. getCustomerOrders(customerNumber), then concatenate the results. However, I cannot seem to figure out how to get db2 to not include terminators {} when building json. The only way I have figured out how to do this is to code a 2nd parameter to remove the object terminators, ie. getCustomerInfo(customerNumber:removeTerminators).
I realize I "could" do this:
{
"customerInfo" : {
"customerNumber" : 123456,
"customerName" : "ACME Shipping",
"customerPhone" : 5555555555
},
"orders": [
{
"orderNumber" : "5555",
"orderTotal" : 123.45
}, {
"orderNumber" : "4444",
"orderTotal" : 321.00
}
]
}
[/PHP]
With the above example, could return an entire customerInfo object, then just concatenate it using "format json" feature in sql. However, I do not have that level of control over the resulting json. The requirement is to make it look like the first result I posted.
Thoughts?
Sample json result
PHP Code:
{
"customer" : 123456,
"customerName" : "ACME Shipping",
"customerPhone" : 5555555555,
"orders": [
{
"orderNumber" : "5555",
"orderTotal" : 123.45
}, {
"orderNumber" : "4444",
"orderTotal" : 321.00
}
]
}
I realize I "could" do this:
{
"customerInfo" : {
"customerNumber" : 123456,
"customerName" : "ACME Shipping",
"customerPhone" : 5555555555
},
"orders": [
{
"orderNumber" : "5555",
"orderTotal" : 123.45
}, {
"orderNumber" : "4444",
"orderTotal" : 321.00
}
]
}
[/PHP]
With the above example, could return an entire customerInfo object, then just concatenate it using "format json" feature in sql. However, I do not have that level of control over the resulting json. The requirement is to make it look like the first result I posted.
Thoughts?
Comment