Challenge - 5 Problems
JSON Data Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2: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;
Attempts:
2 left
💡 Hint
Remember JSON_EXTRACT returns the value as JSON, including quotes for strings.
✗ Incorrect
JSON_EXTRACT returns the value as a JSON string, so string values are returned with quotes.
❓ query_result
intermediate2: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'?Attempts:
2 left
💡 Hint
Compare the extracted JSON string after removing quotes.
✗ Incorrect
JSON_EXTRACT returns a JSON string with quotes, so use JSON_UNQUOTE to compare the actual string value.
📝 Syntax
advanced2:00remaining
Valid JSON path syntax in MySQL
Which of the following JSON path expressions is invalid in MySQL JSON functions?
Attempts:
2 left
💡 Hint
MySQL JSON path does not support recursive descent operator '..'.
✗ Incorrect
MySQL JSON path syntax does not support the recursive descent operator '..', so option D is invalid.
❓ optimization
advanced2: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+?Attempts:
2 left
💡 Hint
MySQL supports indexing generated columns but not JSON columns directly.
✗ Incorrect
MySQL cannot index JSON columns directly but can index generated columns that extract JSON values.
🧠 Conceptual
expert2:00remaining
Behavior of JSON_ARRAY_APPEND with non-array target
Given a JSON column
What happens to the
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?Attempts:
2 left
💡 Hint
JSON_ARRAY_APPEND expects the target path to be an array or null.
✗ Incorrect
If the target path is not an array or null, JSON_ARRAY_APPEND raises an error.