nerdexam
Snowflake

DEA-C02 · Question #133

The following command is run: FLATTEN select * from table(flatten(input => parse_json('{"first_name":"joe", "last_name": "smith" "location": {"state":"co", }}'), recursive => true )) f; How many…

The correct answer is B. 2 rows. B is correct because the JSON string is malformed - it has a missing comma between "smith" and "location", which causes Snowflake's PARSE_JSON to only successfully process the first two valid key-value pairs (first_name and last_name). When FLATTEN with recursive => true…

Data Transformation

Question

The following command is run: FLATTEN select * from table(flatten(input => parse_json('{"first_name":"joe", "last_name": "smith" "location": {"state":"co", }}'), recursive => true )) f; How many rows will be returned?

Options

  • A1 row
  • B2 rows
  • C3 rows
  • D4 rows

How the community answered

(41 responses)
  • A
    7% (3)
  • B
    73% (30)
  • C
    15% (6)
  • D
    5% (2)

Explanation

B is correct because the JSON string is malformed - it has a missing comma between "smith" and "location", which causes Snowflake's PARSE_JSON to only successfully process the first two valid key-value pairs (first_name and last_name). When FLATTEN with recursive => true processes the resulting two-key object, it returns exactly two rows - one per scalar key. Note that Snowflake's lenient JSON parser can tolerate trailing commas (like after "co"), but a missing comma between object members stops parsing early.

A (1 row) is wrong because two key-value pairs are successfully parsed, not one. C (3 rows) would be correct if the JSON were fully valid and FLATTEN ran non-recursively - you'd get one row per top-level key (first_name, last_name, location). D (4 rows) would be correct if the JSON were valid and recursive => true expanded the nested location object - yielding the 3 top-level keys plus the nested state key.

Memory tip: In FLATTEN questions, always inspect the JSON for syntax errors before counting keys - a missing comma is like a roadblock that stops parsing mid-object, silently reducing your expected row count.

Topics

#JSON#FLATTEN function#Semi-structured data

Community Discussion

No community discussion yet for this question.

Full DEA-C02 Practice