I need to get the values from a table in json format , directly using mysql query (no post processing in php etc at application level). Most of the field of the table are integer and its not hard to build a json string for the records , but one column is a text
type and my contain all the garbage .
Is is possible to stringify
that text type column data to build a valid json string ?
query:
select concat('var sp_json= [',
group_concat(
'{"sp_no":',sp_no,',
"sp_group_no":',sp_group_no,',
"sp_weight":',sp_weight,',
"dg_list":[',dg_list,'],
"comments":\'',coalesce(comments,''),'\'}'
order by sp_group_no
),
']') as sp_json
from sp_dg where pm_id=1 group by pm_id
This outputs a javascript json objects etc
var sp_json=[{},,,]
I need way to stringify comments
using a built-in mysql function if there is one. Please share your thoughts .