search

Home  >  Q&A  >  body text

How to operate mysql's JSON?

JSON field content of mysql

"[{"id":"1","name":"a"},{"id":"2","name":"b"},{"id":"3", "name":"c"}]"

How to query the data of name=b?
Note: Mine is a piece of data, a two-dimensional array converted to json

  1. One way is to directly operate json
    Someone has provided select json_extract(json,'$[*].name' ) from table where json_extract(json,'$[* ].name')= "b" ;Method, no effect

2. Another method is to take it out, operate it, and put it back again.

The problem is that the extracted content is as shown in the picture. I have tried various methods but it cannot be operated.

世界只因有你世界只因有你2790 days ago740

reply all(3)I'll reply

  • 大家讲道理

    大家讲道理2017-06-06 09:54:19

    Add another field for query operations. Try not to use the native functions of mysql.

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-06-06 09:54:19

    The content of the json field should not have double quotes in the outermost layer, so it is not a JSON array.

    In addition, it is best to provide complete text content for the content of the JSON field, and the content of the screenshot is incomplete.

    reply
    0
  • PHP中文网

    PHP中文网2017-06-06 09:54:19

    json_extract(json,'$[*].name' )

    What is returned is ["a", "b", "c"] will not match "b".

    Hey, I won’t try to adjust it myself...

    reply
    0
  • Cancelreply