How to get values from MySQL(5.6) column if that contains json document as string

To be able to do what you want to, you need MySQL 5.7.8+. Since 5.7.8 you can use JSON_EXTRACT function to extract a value from a JSON string:

SELECT JSON_EXTRACT('{"id": 14, "name": "Aztalan"}', '$.name');

+---------------------------------------------------------+
| JSON_EXTRACT('{"id": 14, "name": "Aztalan"}', '$.name') |
+---------------------------------------------------------+
| "Aztalan"                                               |
+---------------------------------------------------------+

Taken from here.

In MySQL 5.6 you just can’t get the value you want as MySQL doesn’t know anything about what a JSON object is. So your options are:

  • Upgrade to 5.7.8+
  • Parse the query result with something that handles JSON:
    • Could be PHP json_decode (or equivalent in your language)
    • An online tool like http://json.parser.online.fr/

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)