Module 07 · Lesson 3 of 9Detailed study · about 12 min

Missing keys, JSON null and invalid input

A missing value, an explicit JSON null and invalid JSON are different situations. Keep enough evidence to tell them apart.

Understand the idea

Empty or whitespace-only input also produces SQL NULL when parsed. Therefore TRY_PARSE_JSON(text) IS NULL is not, by itself, a complete classification of malformed versus absent input.

Key ideas in simple English
ConceptWhat it means
SQL NULLNo SQL value; a missing object key can produce it.
JSON nullA present JSON value tested with IS_NULL_VALUE.
TRY_PARSE_JSONReturns SQL NULL when parsing fails.
Original textPreserves the evidence needed to diagnose a rejected record.

A concrete example

{"note":null} explicitly supplies note; {} supplies no note key at all.

Remember: A tolerant parser or cast prevents an exception, but does not certify valid data.

Explain it step by step · full theory

How to apply it

Empty or whitespace-only input also produces SQL NULL when parsed. Therefore TRY_PARSE_JSON(text) IS NULL is not, by itself, a complete classification of malformed versus absent input.

For ingestion, retain original text and assign a rejection reason before publishing typed rows. Distinguish invalid JSON, missing required keys and incompatible types. Do not convert every failure to zero: zero is a real business value.

Words used in this lesson
SQL NULL
No SQL value; a missing object key can produce it.
JSON null
A present JSON value tested with IS_NULL_VALUE.
TRY_PARSE_JSON
Returns SQL NULL when parsing fails.
Original text
Preserves the evidence needed to diagnose a rejected record.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 3

Missing keys, JSON null and invalid input

SQL NULL
JSON null

Read the shape

A missing value, an explicit JSON null and invalid JSON are different situations. Keep enough evidence to tell them apart.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Read the shape

    A missing value, an explicit JSON null and invalid JSON are different situations. Keep enough evidence to tell them apart.

  2. Follow the example

    {"note":null} explicitly supplies note; {} supplies no note key at all.

  3. Verify the result

    A tolerant parser or cast prevents an exception, but does not certify valid data.

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

Manual learning examples; nothing runs on this website. Standalone WITH/SELECT examples supply their own input. Table and file exercises require the first lesson’s L2_OBJECTS_LAB.M7_LAB setup and an authorized warehouse. Select that schema in every session. The final lab requires the supplied events.json to be loaded first.

Observe the three cases

SQL · example
WITH e AS (SELECT PARSE_JSON('{"note":null}') AS p)
SELECT IS_NULL_VALUE(p:note) AS EXPLICIT_JSON_NULL,
 p:missing IS NULL AS MISSING_KEY,
 TRY_PARSE_JSON('{broken') IS NULL AS BAD_PARSE
FROM e;
SELECT TRY_TO_NUMBER('banana') IS NULL AS BAD_NUMBER;

What to expect and why

All four checks return TRUE, but for different reasons. IS_NULL_VALUE tests JSON null; IS NULL tests SQL NULL.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

TRY_TO_NUMBER returns NULL for banana. Should the amount become zero?

Try it yourself

What would you retain for a rejected event?

Compare your reasoning

Retain source identity, original payload, rejection reason and ingestion time so the producer can correct and replay it.

Official sources and curriculum

Module 07 · See module scope