Challenge - 5 Problems
JSON Path Extraction Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Extracting a JSON object using #>
Given the table data with a JSONB column
What is the output of this query?
info containing:{"user": {"name": "Alice", "age": 30}}What is the output of this query?
SELECT info #> '{user}' AS result FROM data;PostgreSQL
CREATE TABLE data (info JSONB); INSERT INTO data VALUES ('{"user": {"name": "Alice", "age": 30}}');
Attempts:
2 left
💡 Hint
The operator #> extracts a JSON object at the specified path as JSON, not as text.
✗ Incorrect
The #> operator extracts the JSON object at the given path as JSONB. Here, the path '{user}' extracts the nested object {"name": "Alice", "age": 30}.
❓ query_result
intermediate2:00remaining
Extracting text from JSON using #>>
Given the same table data with JSONB column
What is the output of this query?
info containing:{"user": {"name": "Alice", "age": 30}}What is the output of this query?
SELECT info #>> '{user,name}' AS result FROM data;PostgreSQL
CREATE TABLE data (info JSONB); INSERT INTO data VALUES ('{"user": {"name": "Alice", "age": 30}}');
Attempts:
2 left
💡 Hint
The #>> operator extracts the value as text, without quotes.
✗ Incorrect
The #>> operator extracts the value at the path as text. The path '{user,name}' points to the string "Alice", which is returned as plain text without quotes.
🧠 Conceptual
advanced2:00remaining
Difference between #> and #>> operators
Which statement correctly describes the difference between the PostgreSQL JSONB operators #> and #>>?
Attempts:
2 left
💡 Hint
Think about the data type each operator returns.
✗ Incorrect
The #> operator returns JSONB data (objects or arrays) at the specified path. The #>> operator returns the value as plain text, useful for extracting scalar values.
📝 Syntax
advanced2:00remaining
Identify the syntax error in JSON path extraction
Which of the following queries will cause a syntax error in PostgreSQL when extracting a JSON path?
Attempts:
2 left
💡 Hint
Check the format of the path argument for #> and #>> operators.
✗ Incorrect
The path argument must be a text array literal enclosed in curly braces. Option A uses a plain string without braces, causing a syntax error.
❓ optimization
expert3:00remaining
Optimizing JSON path extraction in large datasets
You have a large table with a JSONB column
data. You frequently query nested keys using #> and #>> operators. Which approach will improve query performance the most?Attempts:
2 left
💡 Hint
Consider which index type supports JSONB path queries and text extraction efficiently.
✗ Incorrect
GIN indexes support JSONB containment and path queries. Using #>> extracts text values which can be efficiently filtered with GIN indexes. B-tree indexes do not support JSONB well.