Bird
0
0

You wrote this dbt SQL code to extract a nested JSON value:

medium📝 Debug Q14 of 15
dbt - Advanced Patterns
You wrote this dbt SQL code to extract a nested JSON value:
SELECT
  data->'user'->>email AS email
FROM users

But you get an error. What is the likely cause?
AUsing ->> after -> on a JSON object without parentheses
BUsing -> instead of ->> for text extraction
CMissing quotes around 'email' key
DThe JSON column 'data' is not valid JSON
Step-by-Step Solution
Solution:
  1. Step 1: JSON path operators require quoted keys

    Keys in -> and ->> must be string literals enclosed in single quotes.
  2. Step 2: Identify syntax issue

    In data->'user'->>email, email lacks quotes and is interpreted as an identifier (e.g., column name) instead of a JSON key, causing a syntax error. Correct syntax: data->'user'->>'email'.
  3. Final Answer:

    Missing quotes around 'email' key -> Option C
  4. Quick Check:

    JSON keys must be quoted strings [OK]
Quick Trick: Always quote JSON keys in -> and ->> operators [OK]
Common Mistakes:
MISTAKES
  • Forgetting parentheses in chained JSON extraction
  • Misquoting JSON keys
  • Assuming JSON column is invalid without checking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More dbt Quizzes