0
0
MySQLquery~20 mins

JSON data type in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JSON Data Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Extracting a value from JSON column
Given a MySQL table users with a JSON column profile storing data like {"age": 30, "city": "Boston"}, what is the output of this query?
SELECT JSON_EXTRACT(profile, '$.city') AS city FROM users WHERE id = 1;
MySQL
SELECT JSON_EXTRACT(profile, '$.city') AS city FROM users WHERE id = 1;
ANULL
BBoston
C"Boston"
DSyntaxError
Attempts:
2 left
💡 Hint
Remember JSON_EXTRACT returns the value as JSON, including quotes for strings.
query_result
intermediate
2:00remaining
Filtering rows by JSON value
Consider a table orders with a JSON column details storing {"status": "shipped", "quantity": 5}. Which query returns all orders where status is exactly 'shipped'?
ASELECT * FROM orders WHERE JSON_EXTRACT(details, '$.status') = 'shipped';
BSELECT * FROM orders WHERE JSON_UNQUOTE(JSON_EXTRACT(details, '$.status')) = 'shipped';
CSELECT * FROM orders WHERE details->'$.status' = 'shipped';
DSELECT * FROM orders WHERE details->>'$.status' = 'shipped';
Attempts:
2 left
💡 Hint
Compare the extracted JSON string after removing quotes.
📝 Syntax
advanced
2:00remaining
Valid JSON path syntax in MySQL
Which of the following JSON path expressions is invalid in MySQL JSON functions?
A$.store.book[0].title
B$['store']['book'][0]['title']
C$.store.book[*].title
D$.store..book.title
Attempts:
2 left
💡 Hint
MySQL JSON path does not support recursive descent operator '..'.
optimization
advanced
2:00remaining
Indexing JSON columns for faster queries
You want to speed up queries filtering by a JSON key status inside a JSON column data. Which approach is best in MySQL 8.0+?
ACreate a generated column extracting status and index it: ALTER TABLE t ADD COLUMN status VARCHAR(20) AS (JSON_UNQUOTE(JSON_EXTRACT(data, '$.status'))) STORED; CREATE INDEX idx_status ON t(status);
BCreate a fulltext index on the JSON column: CREATE FULLTEXT INDEX idx_data ON t(data);
CCreate a normal index directly on the JSON column: CREATE INDEX idx_data ON t(data);
DUse a trigger to copy status to a separate table and index that table.
Attempts:
2 left
💡 Hint
MySQL supports indexing generated columns but not JSON columns directly.
🧠 Conceptual
expert
2:00remaining
Behavior of JSON_ARRAY_APPEND with non-array target
Given a JSON column info with value {"tags": "new"}, what is the result of:
UPDATE table SET info = JSON_ARRAY_APPEND(info, '$.tags', 'sale') WHERE id = 1;

What happens to the tags key?
AThe query fails with an error because 'tags' is not an array
BThe 'tags' key becomes an array: ["new", "sale"]
CThe 'tags' key remains a string 'new' and 'sale' is appended as a new element
DThe 'tags' key is replaced with the string 'sale'
Attempts:
2 left
💡 Hint
JSON_ARRAY_APPEND expects the target path to be an array or null.