Currently, I am in the process of building a nested JSON object by parsing a query string obtained from an SQL database. This constructed JSON object will then be utilized by Angular to display data in the user interface using angular2-query-builder.
The input query string is as follows: TierLevel = '1' AND CompanyType = '7' AND CompanyService = '23' AND ( City LIKE('%york%') OR City LIKE('%cal%') ) AND ( StateProvince = 3171 OR StateProvince = 475 OR StateProvince = 2239 OR ( Country = 224 AND Country = 1 ) ).
output_JSON_Object = {
condition: 'and',
rules: [
{
field: 'TierLevel',
operator: 'Equals',
value: '1'
},
{
field: 'CompanyType',
operator: 'Equals',
value: '7'
},
{
field: 'CompanyService',
operator: 'Equals',
value: '23'
},
{
condition: 'or',
rules: [
{
field: 'City',
operator: 'Contains',
value: 'york'
},
{
field: 'City',
operator: 'Contains',
value: 'cal'
}
]
},
{
condition: 'or',
rules: [
{
field: 'StateProvince',
operator: 'Equals',
value: '3171'
},
{
field: 'StateProvince',
operator: 'Equals',
value: '475'
},
{
field: 'StateProvince',
operator: 'Equals',
value: '2239'
},
{
condition: 'and',
rules: [
{
field: 'Country',
operator: 'Equals',
value: '224'
},
{
field: 'Country',
operator: 'Equals',
value: '1'
}
]
}
]
}
]
}
Your assistance on this matter would be greatly appreciated. Thank you!