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

Load JSON and Parquet, then query the values

The file format determines how source bytes are read. After loading, query the stored fields using their actual names and types.

Understand the idea

Complete the first lesson’s setup. Save events.json below as UTF-8 and upload it to json/ in M7_FILES. The default JSON format works for these separate documents; do not enable STRIP_OUTER_ARRAY just because a nested items array exists.

Key ideas in simple English
ConceptWhat it means
JSON linesOne complete JSON object per line in this fixture.
Top-level JSON arraySTRIP_OUTER_ARRAY can load its elements as separate records.
ParquetBinary columnar files; do not create them by renaming JSON.
Loaded VARIANTInspect keys and cast the fields required by your query.

A concrete example

Two event documents become two raw rows even though the first contains two items.

Remember: Loading preserves the document grain. Flattening is a separate transformation.

Explain it step by step · full theory

How to apply it

Complete the first lesson’s setup. Save events.json below as UTF-8 and upload it to json/ in M7_FILES. The default JSON format works for these separate documents; do not enable STRIP_OUTER_ARRAY just because a nested items array exists.

The Parquet exercise creates its own tiny file through an unload, so no external fixture generator is required. Use a fresh parquet/run01/ prefix and fresh destination on your first attempt. File readers and producer schemas affect represented types: inspect PAYLOAD before assuming the key case or casting.

Words used in this lesson
JSON lines
One complete JSON object per line in this fixture.
Top-level JSON array
STRIP_OUTER_ARRAY can load its elements as separate records.
Parquet
Binary columnar files; do not create them by renaming JSON.
Loaded VARIANT
Inspect keys and cast the fields required by your query.

See how it works

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

Open the interactive explanation
Interactive explainer1 / 3

Load JSON and Parquet, then query the values

JSON lines
Top-level JSON array

Read the shape

The file format determines how source bytes are read. After loading, query the stored fields using their actual names and types.

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

    The file format determines how source bytes are read. After loading, query the stored fields using their actual names and types.

  2. Follow the example

    Two event documents become two raw rows even though the first contains two items.

  3. Verify the result

    Loading preserves the document grain. Flattening is a separate transformation.

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.

Save events.json

JSON file contents · example
{"event_id":101,"customer":{"name":"Asha","home city":"Pune"},"items":[{"sku":"A","qty":2,"price":10,"tags":["sale","gift"]},{"sku":"B","qty":1,"price":15,"tags":["new"]}],"note":null}
{"event_id":102,"customer":{"name":"Bilal","home city":"Delhi"},"items":[]}

What to expect and why

Two documents on two lines. Save the complete text; do not run it in a SQL worksheet.

Upload through a supported client

SnowSQL / supported client command · example
PUT file:///absolute/path/events.json @L2_OBJECTS_LAB.M7_LAB.M7_FILES/json/ AUTO_COMPRESS=FALSE;

What to expect and why

Replace the local path. Alternatively upload through Snowsight into json/. Keep events.json as the filename.

Load and query JSON

SQL · example
COPY INTO M7_EVENTS_RAW FROM @M7_FILES/json/
 FILES=('events.json') FILE_FORMAT=(FORMAT_NAME='M7_JSON');
SELECT PAYLOAD:event_id::NUMBER AS EVENT_ID,
 PAYLOAD:customer.name::VARCHAR AS CUSTOMER,
 ARRAY_SIZE(PAYLOAD:items) AS ITEM_COUNT
FROM M7_EVENTS_RAW ORDER BY EVENT_ID;

What to expect and why

Expected rows: (101,Asha,2) and (102,Bilal,0). These remain two parent documents.

Create, load and query a small Parquet file

SQL · example
COPY INTO @M7_FILES/parquet/run01/
 FROM (SELECT 101::NUMBER(10,0) AS "event_id", 'Asha'::VARCHAR AS "customer")
 FILE_FORMAT=(TYPE=PARQUET COMPRESSION=SNAPPY);
CREATE TABLE M7_PARQUET_RAW (PAYLOAD VARIANT);
COPY INTO M7_PARQUET_RAW FROM @M7_FILES/parquet/run01/
 FILE_FORMAT=(TYPE=PARQUET);
SELECT PAYLOAD:event_id::NUMBER AS EVENT_ID,
 PAYLOAD:customer::VARCHAR AS CUSTOMER FROM M7_PARQUET_RAW;

What to expect and why

Expected one row: 101, Asha. Quoted export aliases keep lowercase field names. The stage owner can export; a separate exporter needs the appropriate stage WRITE and other access.

Check your understanding

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

A JSON document contains 20 items. A raw VARIANT load necessarily creates 20 rows?

Try it yourself

How would the JSON format change for a file whose outermost value is an array of event documents?

Compare your reasoning

Use a dedicated JSON format with STRIP_OUTER_ARRAY=TRUE when each outer element should become a separate row; keep the existing format for this JSON-lines fixture.

Official sources and curriculum

Module 07 · See module scope