怎么在mysql中解析json,在MySQL中解析JSON

I need help on how to parse JSON data in MySQL.

I can parse a column named config containing data such as:

{"encounterId":"f45bf821-98e1-4496-82ef-047971e168cb","providerId":"38001853-d2e1-4361-9fff-cfca1aedf406","patientId":"f4d04edb-652f-427c-ac25-6fecbda2a0aa","obs":[{"conceptId":"4e903795-ad79-48fc-851e-9e67c9628e6b","value":0.0},{"conceptId":"5300c3e4-3b53-4a0b-874b-3060d18cec9b","value":"Q"},{"conceptId":"dded4485-6160-4791-a13d-16c87f5004dc","value":"000019"},{"conceptId":"4e503f63-caa0-419a-8670-112441d228da","value":"girl"}],"dateCreated":"Dec 5, 2012 9:39:01 AM","formId":"ETAT","locationId":"","created":1354693141902}

by using

select common_schema.get_option(be.config,'encounterid') AS eid

, common_schema.get_option(be.config,'providerid') AS gender

, common_schema.get_option(be.config,'patientid') AS pid

from bencounter be

to get what I need.

However, I am unable to get the data for 'obs' which is several 'rows' of the fields conceptid and value.

Further more any reference to a field after the 'set' of obs returns a null

select common_schema.get_option(be.config,'encounterid') AS eid

, common_schema.get_option(be.config,'providerid') AS gender

, common_schema.get_option(be.config,'patientid') AS pid

, common_schema.get_option(be.config,'formId') AS formid -- THIS RETURNS NULL

from bencounter be

Can some one please help me figure this out.

I would like to solve this directly in MySQL...

Clemens

解决方案

Here's a solution in MySQL 5.7 syntax:

select be.config->'$.encounterId' AS eid

, be.config->'$.providerId' AS gender

, be.config->'$.patientId' AS pid

, be.config->'$.formId' AS formid

from bencounter be \G

Output:

*************************** 1. row ***************************

eid: "f45bf821-98e1-4496-82ef-047971e168cb"

gender: "38001853-d2e1-4361-9fff-cfca1aedf406"

pid: "f4d04edb-652f-427c-ac25-6fecbda2a0aa"

formid: "ETAT"

Remember that field keys in JSON are case-sensitive. For example, 'formId' is not the same as 'formid'.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值