PDE Preparing and Using Data for Analysis Practice Question
You have a BigQuery table `logs` with a column `message` that contains JSON strings. You need to extract the value of the `user_id` field from each JSON string and return it as a separate column. Which function should you use?
⚠ Common exam trap
The trap here is choosing JSON_EXTRACT, which returns a JSON string with quotes, instead of JSON_EXTRACT_SCALAR, which returns the unquoted scalar value.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
JSON_EXTRACT_SCALAR(message, '$.user_id')
The JSON_EXTRACT_SCALAR function is designed to extract scalar values from JSON strings using JSONPath. It returns the value as a STRING, which is ideal for extracting user_id. Other functions either return JSON-formatted strings, rely on brittle regex, or use invalid syntax. For robust JSON parsing in BigQuery, JSON_EXTRACT_SCALAR is the correct choice.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
JSON_EXTRACT_SCALAR(message, '$.user_id')
Why this is correct
JSON_EXTRACT_SCALAR extracts a scalar value from a JSON string using a JSONPath expression. It returns the value as a STRING, which is suitable for extracting user_id. This is the correct function for this scenario because it handles JSON parsing and returns a scalar, not a JSON object.
- ✗
JSON_EXTRACT(message, '$.user_id')
Why it's wrong here
JSON_EXTRACT returns a JSON-formatted STRING, including quotes for string values. For example, it would return '"123"' instead of '123'. While it extracts the value, it does not return a scalar and may require additional parsing. It is not the best choice when a scalar is needed.
- ✗
REGEXP_EXTRACT(message, r'"user_id":\s*"([^"]+)"')
Why it's wrong here
REGEXP_EXTRACT uses a regular expression to extract a substring. While it can work for simple JSON, it is brittle and error-prone for nested or varied JSON structures. It also does not handle escaped characters or different orderings well. The dedicated JSON functions are more robust and recommended.
- ✗
PARSE_JSON(message).user_id
Why it's wrong here
PARSE_JSON converts a JSON string to a JSON data type, but you cannot directly access fields with dot notation in BigQuery SQL. You would need to use JSON_VALUE or similar functions. This syntax is invalid and will cause an error.
About these practice questions
This PDE question is part of Courseiva's 747-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Google Cloud exam blueprint
This PDE practice question is part of Courseiva's free Google Cloud certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PDE exam.