Work with JSON data in MySQL server
July 05, 2024• Edited: July 05, 2024
To work with JSON value in MySQL you can use JSON_VALUE(column, '$.key') function to extract a scalar value from a JSON string.
-
CREATEquery:CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, address JSON ); -
INSERTquery:INSERT INTO users (address) VALUES ('{"street": "123 Main St", "city": "Springfield"}}'), ('{"street": "456 Elm St", "city": "Shelbyville"}}'); -
SELECTquery:SELECT id, JSON_VALUE(address, '$.city') FROM users; -
UPDATEquery:UPDATE users SET address = JSON_SET(address, '$.city', Shelbyville) WHERE id = 1;
Read more about create JSON data , search JSON data , or edit JSON data .