Associate Data Practitioner free question 3 / 10 · Domain 1: Data Preparation and Ingestion
You load order data from a JSON file in Cloud Storage into BigQuery. Each order contains a variable number of line items, and you want each order to become one record. How should the file be structured?
- Join the order objects side by side on one line, separated by commas
- Place the order objects one after another, separated by newline characters
- Expand each order object across several indented lines
- Wrap the order objects in a single array that spans the whole file
Show the answer and explanation
Answer: B
Why this is correct
JSON loaded into BigQuery must be newline-delimited JSON (ndJSON), and each JSON object has to be on a separate line of the file. The line items stay inside their own order object, and the orders are separated from one another by line breaks. This is different from putting everything into one array or pretty-printing an object over several lines.
Why the other options are wrong
"Wrap the order objects in a single array that spans the whole file" … A file-wide array is valid JSON in general, but it is not the one-object-per-line layout that a BigQuery load requires.
"Expand each order object across several indented lines" … Spreading one record over several lines breaks the newline-delimited layout that the load expects, because each object must be on its own line.
"Join the order objects side by side on one line, separated by commas" … Joining objects with commas on one line does not put each object on a separate line, so the file does not follow the required format.
Key point
JSON that is valid in general is not necessarily the file format the load destination requires. For BigQuery, use one JSON object per line.