JSON to SQL

Hello Everyone,
I want to write a service to convert this json in to SQL condition
filterName will be the fieldname for SQL and filtervalue will be the where condition.

{
“filters”: [
{
“insideFilterObject”: true,
“array”: [
{
“filterName”: “Order_Date”,
“displayName”: “Order Date”,
“filterValues”: [
{
“name”: “All”,
“range”: false,
“days”: “0”,
“counter”: 910
},
{
“name”: “This Year”,
“range”: true,
“days”: “-365”,
“counter”: 410
},
{
“name”: “Last Week”,
“range”: true,
“days”: “-7”,
“selected”: true,
“counter”: 48
},
{
“name”: “Custom Date Range”,
“range”: true,
“custom”: true
}
],
“filterType”: “link”,
“queryType”: “Between”
},
{
“filterName”: “Ship_Date”,
“Display Name”: “Ship Date”,
“filterValues”: [
{
“name”: “All”,
“range”: false,
“days”: “0”,
“counter”: 910
},
{
“name”: “This Year”,
“range”: true,
“days”: “-365”,
“counter”: 410
},
{
“name”: “Last Week”,
“range”: true,
“days”: “-7”,
“counter”: 48
},
{
“name”: “Custom Date Range”,
“range”: true,
“custom”: true
}
],
“filterType”: “link”,
“queryType”: “Between”
}
]
},
{
“insideFilterObject”: false,
“filterName”: “Order_Status”,
“displayName”: “Current Status”,
“filterValues”: [
{
“name”: “Ordered”,
“value”: “Ordered”
},
{
“name”: “In Process”,
“value”: “In Process”
},
{
“name”: “Shipped”,
“value”: “Shipped”
},
{
“name”: “Issues”,
“value”: “Issues”
},
{
“name”: “Delivered”,
“value”: “Delivered”
},
{
“name”: “Invoiced”,
“value”: “Invoiced”
}
],
“filterType”: “checkbox”,
“queryType”: “In”
},
{
“insideFilterObject”: true,
“filterName”: “Quantity_Ordered”,
“displayName”: “Quantity”,
“filterValues”: [
{
“name”: “More than”,
“value”: “>”
},
{
“name”: “Less than”,
“value”: “<”
},
{
“name”: “Equal to”,
“value”: “=”
}
],
“filterType”: “Comparison”,
“queryType”: “In”
},
{
“insideFilterObject”: true,
“filterName”: “Plan_Code”,
“displayName”: “Sites”,
“filterValues”: [
{
“name”: “Norcross”,
“value”: “2155”
},
{
“name”: “Covington”,
“value”: “4390”
}
],
“filterType”: “select”,
“queryType”: “In”
}
]
}

Hi Rohit,

one option might be to convert json to xml and then extract the neccessary data from XML using XQuery.

For the Json->XML conversion you might want to check the following link:

This can be wrapped in a java service.

Regards,
Holger

@ Rohit,

You can make use of JSON API services present in WmPublic. Convert the JSON string to IS doc and then from a sql query (custom/dynamic) by doing the variable substitution.

Else you may have to write some custom java service to parse the json string. Let us know what is your approach and thought process to this requirement.

1 Like