How to JSON extract from dynamic key value pair in MySQL?

前端 未结 4 2125
暖寄归人
暖寄归人 2021-01-25 22:40

I have the user table with user_id and user_details. it contains the JSON data in string format as shown below:

[{\"name\":\"question-1\",\"value\":\"sachin\",\"         


        
4条回答
  •  自闭症患者
    2021-01-25 23:08

    Another answer given by How to extract rows from a json array using the mysql udf json_extract 0.4.0? is to parse yourself the JSON with common_schema. Pretty tricky if you are not used to complex SQL.

    You could create an own aggregated table as proposed in topic List all array elements of a MySQL JSON field if you know how many elements will be given by the field but I guess this is not your case.

    However, it seems better, as mentioned in both answers, not to store such json lists in your SQL database. Maybe could you make a related table containing one line per each dictionary and then link it to your main table with a foreign key.

提交回复
热议问题