Snowflake semi-structured interview questions: VARIANT, FLATTEN and JSON
Reviewed by Mark Dickie · Last updated
5 questions on this page you can answer and see marked on the spot. Go to the first one
Snowflake semi-structured data is JSON, Avro, ORC or Parquet loaded into VARIANT, OBJECT or ARRAY columns and queried without a fixed schema. Interviewers test whether you can pull nested fields out with colon notation, cast them to typed values, and flatten arrays into rows. Most tricky questions turn on NULL behaviour, specifically the gap between a missing key and a JSON null, and on when FLATTEN is required.
What does a Snowflake semi-structured interview test?
| Topic | Syntax | What interviewers check |
|---|---|---|
| Path access | raw:customer.address.city | The result is VARIANT, so it needs a cast before it behaves like text |
| Typed casts | raw:order_total::NUMBER(10,2) | TRY_CAST returns NULL on a bad value, while :: raises an error |
| Array explode | FROM t, LATERAL FLATTEN(input => t.raw:items) | Empty arrays drop the row unless you pass OUTER => TRUE |
| Null checks | IS_NULL_VALUE(raw:discount) | A JSON null is not SQL NULL, so IS NULL can give the wrong answer |
How do you practise VARIANT and FLATTEN by hand?
- Create a table with one VARIANT column, then load a JSON file with COPY INTO using a file format of TYPE = JSON.
- Select nested keys with colon notation, then cast two of them with ::NUMBER and ::DATE.
- Flatten the items array with LATERAL FLATTEN, then rebuild one row per order with ARRAY_AGG.
- Insert one row where a key is absent and another where it is JSON null, then compare them with IS_NULL_VALUE.
- Run a filter on a nested key and open the query profile to see how many micro-partitions were scanned.
Key facts
- Tarmac has 11 Snowflake interview questions on this topic, 10 of them on this page, at difficulty 1–5 of 5.
- Tarmac tracked 430 job postings asking for Snowflake in November 2026.
- Roles asking for Snowflake advertise a median base salary of £75,000, across 105 job postings as of November 2026.
- Tarmac last reviewed these Snowflake interview questions on 30 November 2026.
At a glance
| Questions | 10 shown · 11 in the bank |
|---|---|
| Difficulty | 1–5 of 5 |
| Formats | Multiple choice, Flashcard, Code output, Ordering, True / false, Find the bug, Fill in the blank, Short answer, Coding exercise |
| Interactive | 1 run your code against tests, in the app |
What you'll review
- flatten
- json parsing
- variant type
Practice questions
Try one before you open the answer. Pick an option and press Check; it's marked on the spot.
In Snowflake, you run SELECT f.??? FROM t, LATERAL FLATTEN(input => t.v:items) f; where v:items is a JSON array. Which FLATTEN output column holds each array element's actual content?#
Options
Show answer
The VALUE column of Snowflake's FLATTEN output holds each array element's content, as a VARIANT. INDEX gives the element's zero-based position, KEY is only filled in when you flatten objects (it is NULL for arrays), and SEQ numbers the input records. That's why queries usually select f.value and often cast it, for example f.value::string.
FLATTEN returns the fixed columns SEQ, KEY, PATH, INDEX, VALUE and THIS. VALUE holds the element itself, as a VARIANT. INDEX is the element's zero-based position in the array. KEY is only filled in when you flatten an object, so it is NULL for array elements. SEQ is a unique number for each input record, not the element. So f.value is the column you select to get each array element.
In Snowflake, which function turns a JSON string such as '{"a": 1}' into a VARIANT value you can query with path notation?#
Show answer
PARSE_JSON. For example, SELECT PARSE_JSON('{"a": 1}'):a; returns 1. It takes a JSON-formatted string and returns a VARIANT. If the string is not valid JSON it raises an error, while TRY_PARSE_JSON returns NULL instead.
PARSE_JSON is the standard Snowflake function for turning JSON text into a VARIANT. Once the text is a VARIANT, you can reach nested fields with colon or bracket path notation. Knowing this function is basic recall for working with semi-structured data in Snowflake.
Querying a VARIANT column with a path that does not exist in the JSON — what does this return?#
-- Table j has one row: v = PARSE_JSON('{"name": "Ada"}')
SELECT v:name::string AS name,
v:age::int AS age
FROM j;Options
Show answer
name = 'Ada', age = NULL — a missing path resolves to SQL NULL, not an error
Path access on a VARIANT is forgiving: v:name navigates into the JSON and returns the value if the key exists, or a JSON null / SQL NULL if it doesn't — it never raises an error for a missing key. So v:name::string yields 'Ada', and v:age::int yields NULL because the age key isn't present in the parsed object. This is why the claim that an error is raised is wrong (no error) and the claim that missing numeric paths default to zero is wrong (there is no implicit zero default — absence is NULL, not 0). The claim that both columns are NULL because mixing existing and missing paths invalidates the row misstates the semantics: each path is evaluated independently, so a missing path on one column doesn't affect the other. This null-tolerant access is a deliberate feature for schema-on-read: semi-structured documents often have optional or evolving fields, and Snowflake lets you select them without guarding every path, surfacing absence as NULL. The casts (::string, ::int) convert the extracted VARIANT into typed SQL columns.
In Snowflake, the VARIANT column raw holds JSON like {"customer": {"orders": [{"amount": "42.50"}, {"amount": "10"}]}}. Put the fragments in order so they form one expression that returns the first order's amount as a NUMBER.#
Put these in order
Show answer
The Snowflake expression is raw:customer.orders[0].amount::NUMBER(10,2). It starts with the VARIANT column, uses a colon for the first-level key, dots for nested keys, and a zero-based bracket index for the array element. The :: cast goes at the end, so it turns the final VARIANT value into a NUMBER.
A Snowflake semi-structured path starts with the VARIANT column name. A colon then picks the first-level key (raw:customer), and dot notation steps into nested keys (.orders). Square brackets with a zero-based index select an array element ([0]), and another dot reads that element's field (.amount). The :: cast comes last because it applies to the VARIANT value the full path returns, turning the JSON string "42.50" into a NUMBER. Put together: raw:customer.orders[0].amount::NUMBER(10,2).
In Snowflake, table orders has a VARIANT column v. One row has v = PARSE_JSON('{"id": 7, "items": []}'). With the default arguments of FLATTEN, the query SELECT o.v:id, f.value FROM orders o, LATERAL FLATTEN(input => o.v:items) f; still returns one row for order 7, with f.value set to NULL.#
Options
Show answer
Snowflake's FLATTEN drops rows whose array is empty by default, so the statement is false. The default is OUTER => FALSE, which makes FLATTEN produce zero rows for an empty array, empty object or NULL input. The lateral join then removes the parent row. Pass OUTER => TRUE to keep the row, with NULL in the KEY, INDEX and VALUE columns.
FLATTEN defaults to OUTER => FALSE. With that setting, an input that is an empty array, an empty object, or NULL (or a missing path) produces no rows. The lateral join then behaves like an inner join, so order 7 is missing from the result entirely. To keep the row with NULL values in the FLATTEN columns, write FLATTEN(input => o.v:items, OUTER => TRUE). That makes FLATTEN emit exactly one row with NULL KEY, INDEX and VALUE, which works like a left outer join.
In Snowflake, this query is supposed to return user_id = 42 and action = 'login'. Instead, user_id comes back NULL and there is no error. Which line contains the bug?#
CREATE TABLE events (payload VARIANT);
INSERT INTO events SELECT PARSE_JSON('{"userId": 42, "action": "login"}');
SELECT
payload:userid::NUMBER AS user_id,
payload:action::STRING AS action
FROM events;Show answer
The bug is on line 4.
In Snowflake, SQL identifiers like column names are case-insensitive, but the JSON key names used in VARIANT path notation are case-sensitive. The JSON stores the key as userId, so payload:userid points to a key that doesn't exist. A missing path quietly returns NULL instead of raising an error, and casting NULL to NUMBER is still NULL. The fix is payload:userId::NUMBER, or payload:"userId". Line 5 works because action matches the stored key exactly. Line 2 is also fine: it inserts a VARIANT using INSERT ... SELECT, which is the pattern Snowflake requires.
Given a single VARIANT column holding a JSON array of tags, what does this query return?#
-- Table t has one row: v = PARSE_JSON('{"tags": ["a", "b", "c"]}')
SELECT f.value::string AS tag
FROM t,
LATERAL FLATTEN(input => t.v:tags) AS f
ORDER BY tag;Options
Show answer
Three rows: 'a', 'b', 'c'
LATERAL FLATTEN expands a semi-structured value into one row per element. Here t.v:tags uses the colon path operator to pull the tags array out of the VARIANT, and FLATTEN produces three rows, one per array element, exposing each element through the VALUE column of the flatten output. Casting f.value::string strips the VARIANT's JSON quoting and yields the plain strings a, b, c — so the option that keeps them quoted is wrong because of the explicit ::string cast. FLATTEN works on arrays and objects (and nested structures), so the option claiming FLATTEN cannot be applied to an array is wrong. The option describing not flattening at all is wrong. ORDER BY then sorts them alphabetically, giving rows a, b, c. This array-to-rows pattern via LATERAL FLATTEN is the canonical way to shred JSON arrays into relational rows in Snowflake.
Table raw_orders(id INT, payload STRING) holds JSON text. Some payloads are malformed, and some have an empty or missing items array. Complete this Snowflake query so that: (1) malformed JSON becomes NULL instead of failing the query, (2) every order still produces at least one output row, even when it has no items, and (3) each item's sku is extracted.#
Show answer
Table raw_orders(id INT, payload STRING) holds JSON text. Some payloads are malformed, and some have an empty or missing items array. Complete this Snowflake query so that: (1) malformed JSON becomes NULL instead of failing the query, (2) every order still produces at least one output row, even when it has no items, and (3) each item's sku is extracted.
SELECT o.id,
f.**value**:sku::STRING AS sku
FROM raw_orders o,
LATERAL FLATTEN(
INPUT => **TRY_PARSE_JSON**(o.payload):items,
**OUTER** => TRUE
) f;
TRY_PARSE_JSON returns NULL for invalid JSON text. Plain PARSE_JSON would raise an error and abort the whole query. FLATTEN normally drops input rows whose input is NULL, missing or an empty array. OUTER => TRUE keeps one row for each of those, with NULLs in the output columns, so every order still appears. FLATTEN returns the columns SEQ, KEY, PATH, INDEX, VALUE and THIS. Each array element is in the VALUE column, so f.value:sku::STRING pulls the sku out of each item.
In Snowflake, table orders(id INT, v VARIANT) has 3 rows: id=1 v = {"items":[{"sku":"A"},{"sku":"B"}]}, id=2 v = {"items":[]}, id=3 v = {} (no items key). An engineer runs SELECT o.id, f.value:sku FROM orders o, LATERAL FLATTEN(input => o.v:items) f; to report every order with its SKUs, and orders 2 and 3 are missing from the result. Explain why. Give the exact fix, and say what the fixed query returns for orders 2 and 3, including the values of f.value, f.index and f.key. Then explain how FLATTEN(input => o.v, RECURSIVE => TRUE) on order 1 reports the path of the element whose sku is B, and what INDEX shows for an object field compared with an array element.#
Show answer
LATERAL FLATTEN works like an inner join. It produces no rows when the input is an empty array (order 2), a missing path or NULL (order 3), or a scalar that can't be expanded, so the parent row is dropped. The fix is FLATTEN(input => o.v:items, OUTER => TRUE). With OUTER, the function emits exactly one row for each input that expands to zero rows, and every output column (VALUE, INDEX, KEY, and so on) is NULL. So orders 2 and 3 each appear once with NULL for value:sku, value, index and key. (A LEFT JOIN on a lateral FLATTEN isn't the idiomatic fix; OUTER => TRUE is.) With RECURSIVE => TRUE, FLATTEN expands every nested level, and the PATH column shows the full path from the input root. The element with sku B is at path items[1], and its sku field is at items[1].sku. INDEX is the zero-based array position for array elements, for example 1 for the second element. INDEX is NULL for object fields, which fill KEY instead, while KEY is NULL for array elements.
Snowflake's FLATTEN defaults to OUTER => FALSE, which drops any input row that produces no expansion. That happens for empty arrays and for missing or NULL paths. Setting OUTER => TRUE keeps one row with all FLATTEN output columns set to NULL. In recursive mode, PATH holds the full path from the input root (such as items[1].sku). INDEX is filled only for array elements and KEY only for object fields.
In Snowflake, LATERAL FLATTEN(input => v, RECURSIVE => TRUE) walks a VARIANT and reports a PATH for every element. Write a Python function that reproduces the leaf rows of that output for a JSON string.#
Starter code
import json
def flatten_paths(s):
data = json.loads(s)
# TODO: recursively walk objects/arrays and build Snowflake-style paths
return []
Your solution must pass
- nested object
- array with object and null
This one is written and run, not read. Solve it in the app and your code is executed against these tests and the hidden ones.
Related interview questions
Job market
See snowflake salaries and hiring demand from live job postings.
The other 1 question
This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 1 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.
Free · the whole bank · 100 answers per 30 days, each marked with written feedback