The JSON data type in MySQL is used to store structured data in JavaScript Object Notation format. It allows you to store arrays, objects, and nested values efficiently inside a table column.
The JSON data type is defined at table creation time. MySQL internally stores JSON in a binary format for faster access.
-- Creating a table with a JSON column
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
profile JSON
);
-- Inserting JSON data into the table
INSERT INTO users (profile)
VALUES ('{"name":"Raj","age":25,"skills":["SQL","Python"]}');
-- Selecting full JSON data
SELECT profile FROM users;
Test how MySQL extracts data. Edit the JSON below and write a path (like $.name) to see the result.
The JSON value is stored as a single column but internally parsed by MySQL. You can retrieve the full JSON or extract specific values using JSON functions.