Published · By Henry Palma
Databricks Data Engineer Associate Practice Quiz, Lesson 5: Nested JSON, explode and explode_outer
Practice quiz for the Databricks Data Engineer Associate exam, Lesson 5: explode versus explode_outer, posexplode, multiLine JSON, and using from_json.
Exam-style question: A table has four orders. One has two items, one has one item, one has an empty array, and one has no items at all. You explode the items column. How many rows come back? Three. explode returns one row per array element and drops rows whose array is null or empty. This post is the practice quiz companion to Lesson 5 of the Databricks Data Engineer Associate exam prep series. It covers two sections of the August 2026 exam guide: Section 2, Data Ingestion and Loading (21% of the exam), and Section 3, Data Transformation and Modeling (22% of the exam).

Watch the full Lesson 5: PySpark explode and Nested JSON video if you want the walkthrough, then use this quiz to check yourself.
The written lesson companion is here: Lesson 5: PySpark explode and Nested JSON.
The notebook and cheat sheet are in the A05 folder on GitHub. The PDF cheat sheet is in the same folder.
This is independent study material, not official Databricks training. The eight questions below are original practice items written by Build and Teach from the public exam guide and Databricks documentation. They are not real exam questions and are not affiliated with or endorsed by Databricks.
What this quiz covers
Nested JSON shows up in two exam sections: ingesting semi-structured data, and turning arrays and structs into rows and columns. explode returns one row per array element and drops rows whose array is null or empty. explode_outer keeps those rows, with a null element, so every order stays in the result. posexplode returns pos and col, and the position starts at zero. Like explode, it skips null and empty arrays. Key and value columns come from exploding a map, not from posexplode.
Dot notation reads fields from a struct, including nested structs such as customer.address.city, and it never changes the row count. Only exploding an array turns elements into rows. When the JSON sits in a string column, parse it first with fromjson and a schema. schemaof_json can derive a schema from a sample. Then dot notation works again.
The plain JSON reader expects one complete record per line. A pretty-printed document that spans many lines needs the multiLine option set to true, or you get corrupt records. Type inference also differs: the plain JSON reader infers longs, doubles, structs and arrays, while Auto Loader infers JSON columns as strings unless cloudFiles.inferColumnTypes is true.
Pause the video when the timer shows, pick A, B, C or D, then check the answer. Seven or more of the eight questions right means you are ready for this section.
Practice questions from the quiz video
These are the eight questions from the quiz video, with answers and explanations.
Question 1
Four orders have items [A1, B2], [C3], [] and null. How many rows does explode on items return?
- A) 4
- B) 3
- C) 5
- D) 2
Answer: B. explode returns one row per element and drops rows whose array is null or empty: two rows plus one row.
Question 2
What does explode_outer do that explode does not?
- A) Numbers each element, starting at zero
- B) Keeps rows whose array is null or empty
- C) Expands a struct into columns
- D) Parses a JSON string into a struct
Answer: B. explode_outer still returns one row when the array is null or empty, with null for the element, so every order is kept.
Question 3
posexplode returns which columns, and where does the position start?
- A) index and value, starting at 1
- B) key and value, starting at 0
- C) pos and col, starting at 0
- D) pos and col, starting at 1
Answer: C. posexplode returns pos and col, and the position starts at zero. Like explode, it skips null and empty arrays. key and value come from exploding a map.
Question 4
spark.read.json on a pretty-printed JSON file that spans many lines returns corrupt records. What is the fix?
- A) Set cloudFiles.inferColumnTypes
- B) Set the multiLine option to true
- C) Wrap the read in from_json
- D) Use explode_outer
Answer: B. By default, the JSON reader expects one complete record per line. A document spanning many lines needs multiLine set to true.
Question 5
How does schema inference differ between the plain JSON reader and Auto Loader?
- A) Both infer JSON columns as strings
- B) Both infer real types
- C) Reader: real types. Auto Loader: strings, unless inferColumnTypes
- D) Auto Loader infers decimals, the reader strings
Answer: C. The plain JSON reader infers long, double, structs and arrays. Auto Loader infers JSON columns as strings unless cloudFiles.inferColumnTypes is true.
Question 6
The tags column holds these arrays. How many rows does this return?
# 1001 ["web", "promo"] 1002 ["store"]
# 1003 [] 1004 ["web"]
orders.select("orderid", explodeouter("tags")) ```
- A) 4
- B) 5
- C) 3
- D) 6
Answer: B. Two rows for 1001, one for 1002, one for 1004, and explode_outer keeps 1003 with a null tag. Plain explode would return 4.
Question 7
customer is a struct with an address struct inside. You select customer.address.city from the four orders. How many rows come back?
- A) 4
- B) 8
- C) 3
- D) One per distinct city
Answer: A. Dot notation reads fields from a struct and never changes the row count. Only exploding an array turns elements into rows.
Question 8
In PySpark, API responses sit as JSON text in a string column. To reach customer.address.city, what comes first?
- A) explode the string column
- B) from_json with a schema, to get a struct
- C) Set multiLine to true
- D) posexplode the string column
Answer: B. fromjson turns a JSON string column into a struct, using a schema (schemaof_json can derive one from a sample). Then dot notation works again.
Practical tips
The memory trick from the video: outer keeps the outsiders. The empty array and the null stay in.
Count carefully on explode questions. Add one row per element, then drop (or keep) the empty and null arrays, depending on whether the function is explode or explode_outer.
If the payload is still a JSON string, explode is the wrong first step. Parse with from_json first. If a file read returns corrupt records on pretty-printed JSON, look at multiLine.
Key takeaways
explodedrops null and empty arrays.explode_outerkeeps those rows with a null element.posexplodereturnsposandcol, starting at zero, and it also skips null and empty arrays.- Dot notation on a struct does not change the row count.
- Pretty-printed JSON files need
multiLineset to true. Auto Loader infers JSON as strings unless you turn oninferColumnTypes. - A JSON string column needs
from_json(with a schema) before you can use dot notation.
Check your understanding
1. Three orders have items [A, B], [] and null. How many rows does explode_outer on items return?
- A) 2
- B) 3
- C) 4
- D) 1
2. You want the position of each tag in an array, starting at zero. Which function fits, and what columns does it return?
- A)
explode, which returnskeyandvalue - B)
posexplode, which returnsposandcol - C)
posexplode, which returnsindexandvaluestarting at 1 - D)
explode_outer, which returnsposandcol
3. customer is a struct with a nested address struct. You select customer.address.city from 50 orders. How many rows come back?
- A) 50
- B) One row per city
- C) 50 times the number of address fields
- D) Only the orders whose address is not null
4. A pretty-printed JSON file spans several lines per record, and spark.read.json returns corrupt records. What is the fix?
- A) Wrap the file read in
from_json - B) Set the
multiLineoption to true - C) Use
explode_outeron the file - D) Set
cloudFiles.inferColumnTypes
5. API responses are stored as JSON text in a string column named payload. You need payload.customer.city. What comes first?
- A)
explodethe string column - B)
from_jsonwith a schema, to get a struct - C) Set
multiLineto true on that column - D)
posexplodethe string column
Answer key
- C.
explode_outerreturns two rows for[A, B], plus one row for the empty array and one row for the null array, which is 4. Plainexplodewould return 2. - B.
posexplodereturnsposandcol, and the position starts at zero. - A. Dot notation reads struct fields and does not change the row count. All 50 orders come back.
- B. The JSON reader expects one record per line unless
multiLineis true. - B.
from_jsonturns the string into a struct. After that, dot notation can reachcustomer.city.