How to store and query JSON data in MySQL?
Stores JSON documents and queries keys using JSON_EXTRACT and inline -> operators.
CREATE TABLE user_profiles (
user_id INT PRIMARY KEY,
meta JSON
);
INSERT INTO user_profiles VALUES
(1, '{"theme": "dark", "notifications": true, "skills": ["MySQL", "PHP"]}');
-- Extract JSON attributes using column->'$.key' operator
SELECT
user_id,
meta->'$.theme' AS theme_setting,
JSON_EXTRACT(meta, '$.skills[0]') AS primary_skill
FROM user_profiles;+---------+---------------+---------------+ | user_id | theme_setting | primary_skill | +---------+---------------+---------------+ | 1 | "dark" | "MySQL" | +---------+---------------+---------------+