Challenge - 5 Problems
JSON vs JSONB Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Difference in Storage Format
Which statement correctly describes the difference in storage format between JSON and JSONB in PostgreSQL?
Attempts:
2 left
💡 Hint
Think about how the data is saved internally and how that affects performance.
✗ Incorrect
JSON stores data as plain text, which means it keeps the original formatting. JSONB stores data in a binary format, which allows faster processing and indexing.
❓ query_result
intermediate2:00remaining
Query Result Difference on Duplicate Keys
Given a table with a JSON and a JSONB column both containing the value '{"a":1, "a":2}', what will be the result of selecting these columns?
PostgreSQL
SELECT json_col, jsonb_col FROM test_table;
Attempts:
2 left
💡 Hint
Consider how JSONB handles duplicate keys compared to JSON.
✗ Incorrect
JSON preserves duplicate keys as text, so it returns both. JSONB removes duplicates and keeps the last key-value pair.
❓ optimization
advanced2:00remaining
Indexing Performance
Which indexing method is supported only by JSONB and not by JSON in PostgreSQL?
Attempts:
2 left
💡 Hint
Think about which index type helps with fast key/value lookups inside JSON data.
✗ Incorrect
JSONB supports GIN indexes which allow efficient searching inside the JSON structure. JSON does not support GIN indexing.
🔧 Debug
advanced2:00remaining
Error When Using JSON Functions
Which option will cause an error when trying to use the JSONB containment operator '@>' on a JSON column?
PostgreSQL
SELECT * FROM test_table WHERE json_col @> '{"key": "value"}';
Attempts:
2 left
💡 Hint
Check if the operator '@>' is supported for the data type used.
✗ Incorrect
The '@>' operator is supported for JSONB but not for JSON type, so using it on a JSON column causes an operator does not exist error.
🧠 Conceptual
expert3:00remaining
When to Prefer JSON over JSONB
In which scenario is it better to use JSON instead of JSONB in PostgreSQL?
Attempts:
2 left
💡 Hint
Think about what JSON preserves that JSONB does not.
✗ Incorrect
JSON preserves the exact input text including whitespace and key order, which JSONB does not. This is useful when the original formatting matters.