Hey guys,
I'm having trouble parsing data I'm retrieving from a database.
The call I'm making is:
"SELECT TOP 1 WITH TIES <blah blah blah> WHERE packaged_products.pro_id = :productID AND pricing_sheets.code = :priceSheetCode AND packaged_products.delivery = 'Y' ORDER BY row_number() over (partition by packaged_products.pkp_id order by pricing_rules.effective_date desc)"
I get the correct data I am looking for back and return it from the xbasic function like this:
dim rs as sql::resultset
rs = cn.resultset
dim json as c
json = rs.ToJSONObjectSyntax()
nameOfFunction = json
Here is the data I am getting:
{
"value": "{"prs_id" : "50", "code" : "2", "description" : "COF coffeename 12oz", "pkp_id" : "5655", "price_rule" : "AB", "price_amount" : "6.4", "price_percent" : null, "effective_date" : "04/26/2021 12:00:00 000 am"}\r\n{"prs_id" : "50", "code" : "2", "description" : "COF coffeename 12oz", "pkp_id" : "18", "price_rule" : "AB", "price_amount" : "200.9", "price_percent" : null, "effective_date" : "04/26/2021 12:00:00 000 am"}"
}
This is the data I want. When I go to parse this data it throws an error:
Script: json_parse() line: 53
Error parsing json: Nothing should follow the root object or array
I understand what is happening, the call is getting 2 results, which I need, but it is formatting them as 2 seperate jsons with \r\n seperating them. It seems that the results need to be in an array instead of two jsons appended by \r\n
I'm just not sure why it is doing this or how I should properly fix it. I have done plenty of sql queries using xbasic functions in the past with a lot of success, this time it seems to be fighting me. Is it because of the SELECT TOP 1 WITH TIES expecting only 1 result? Since I partition by packaged products id it allows multiple results, 1 for each unique packaged product.
Any help with this would be very appreciated! If you have any other questions let me know, I tried to give all data I thought might be helpful.
Thanks!
I'm having trouble parsing data I'm retrieving from a database.
The call I'm making is:
"SELECT TOP 1 WITH TIES <blah blah blah> WHERE packaged_products.pro_id = :productID AND pricing_sheets.code = :priceSheetCode AND packaged_products.delivery = 'Y' ORDER BY row_number() over (partition by packaged_products.pkp_id order by pricing_rules.effective_date desc)"
I get the correct data I am looking for back and return it from the xbasic function like this:
dim rs as sql::resultset
rs = cn.resultset
dim json as c
json = rs.ToJSONObjectSyntax()
nameOfFunction = json
Here is the data I am getting:
{
"value": "{"prs_id" : "50", "code" : "2", "description" : "COF coffeename 12oz", "pkp_id" : "5655", "price_rule" : "AB", "price_amount" : "6.4", "price_percent" : null, "effective_date" : "04/26/2021 12:00:00 000 am"}\r\n{"prs_id" : "50", "code" : "2", "description" : "COF coffeename 12oz", "pkp_id" : "18", "price_rule" : "AB", "price_amount" : "200.9", "price_percent" : null, "effective_date" : "04/26/2021 12:00:00 000 am"}"
}
This is the data I want. When I go to parse this data it throws an error:
Script: json_parse() line: 53
Error parsing json: Nothing should follow the root object or array
I understand what is happening, the call is getting 2 results, which I need, but it is formatting them as 2 seperate jsons with \r\n seperating them. It seems that the results need to be in an array instead of two jsons appended by \r\n
I'm just not sure why it is doing this or how I should properly fix it. I have done plenty of sql queries using xbasic functions in the past with a lot of success, this time it seems to be fighting me. Is it because of the SELECT TOP 1 WITH TIES expecting only 1 result? Since I partition by packaged products id it allows multiple results, 1 for each unique packaged product.
Any help with this would be very appreciated! If you have any other questions let me know, I tried to give all data I thought might be helpful.
Thanks!
Comment