Parse JSON in MySQL

前端 未结 3 1646
滥情空心
滥情空心 2020-12-16 08:17

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         


        
3条回答
  •  时光说笑
    2020-12-16 08:45

    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'.

提交回复
热议问题