我的表中的行如下所示:
template_id template_name default_job_name additional_tasks
1 Indiana Courts Hearing [{"extra_task_id":3,"task_name":"Project Monitoring","task_type":12,"task_notes":"","client_price":null,"ic_cost":null},{"extra_task_id":4,"task_name":"Do Some stuff","task_type":9,"task_notes":"Note","client_price":12,"ic_cost":6}]
我希望以JSON格式返回表:
select template_id, template_name, default_job_name, additional_tasks
from templates_realtime
FOR JSON PATH
我的JSON如下所示:
[{
"template_id": 1,
"template_name": "Indiana Courts",
"default_job_name": "Hearing",
"additional_tasks": "[{\"extra_task_id\":3,\"task_name\":\"Project Monitoring\",\"task_type\":12,\"task_notes\":\"\",\"client_price\":null,\"ic_cost\":null},{\"extra_task_id\":4,\"task_name\":\"Do Some stuff\",\"task_type\":9,\"task_notes\":\"Note\",\"client_price\":12,\"ic_cost\":6}]"
}]
如您所见,additional_tasks仍然是一个字符串,我似乎不知道如何将该字段与其他字段一起转换为JSON,我期待得到以下结果:
[{
"template_id": 1,
"template_name": "Indiana Courts",
"default_job_name": "Hearing",
"additional_tasks": [{
"extra_task_id": 3,
"task_name": "Project Monitoring",
"task_type": 12,
"task_notes": "",
"client_price": null,
"ic_cost": null
}, {
"extra_task_id": 4,
"task_name": "Do Some stuff",
"task_type": 9,
"task_notes": "Note",
"client_price": 12,
"ic_cost": 6
}]
}]
1条答案
按热度按时间wh6knrhe1#
使用
json_query()
将现有JSON嵌入到JSON结果集中,例如:其结果为: