MySQL provides powerful JSON functions to store, read, update, and manipulate JSON data directly inside database columns. These functions are widely used in modern applications where flexible schema and nested data structures are required.
JSON data type$.keyJSON_EXTRACT(json_doc, path)-> and ->> operatorsJSON_OBJECT(), JSON_ARRAY()JSON_SET(), JSON_REPLACE(), JSON_REMOVE()
-- Creating table with JSON column
CREATE TABLE employees (
id INT PRIMARY KEY,
name VARCHAR(50),
profile JSON
);
-- Inserting JSON data
INSERT INTO employees VALUES
(1,'Amit','{"city":"Pune","skills":["SQL","Python"],"experience":5}');
-- Reading JSON value using arrow operator
SELECT profile->>'$.city' AS city FROM employees;
-- Extracting array from JSON
SELECT JSON_EXTRACT(profile,'$.skills') FROM employees;
-- Updating JSON key value
UPDATE employees
SET profile = JSON_SET(profile,'$.city','Mumbai')
WHERE id = 1;
The JSON functions allow you to read nested values, update individual keys without rewriting entire JSON, and return structured data directly from queries.
Think of JSON as a document inside a column where each key behaves like a mini-column. Paths like $.skills[0] directly access array values.
JSON_VALID()->> for scalar values