Ultimate access to all questions.
Upgrade Now 🚀
Sign in to unlock AI tutor
Consider a DataFrame df with a column data containing JSON strings. How would you extract the field user_id from these JSON strings into a new column named extracted_user_id using Spark? Provide the code snippet.
df
data
user_id
extracted_user_id
A
df.withColumn('extracted_user_id', from_json(col('data'), 'user_id'))
B
df.select(from_json(col('data'), 'user_id').alias('extracted_user_id'))
C
df.withColumn('extracted_user_id', get_json_object(col('data'), '$.user_id'))
D
df.select(get_json_object(col('data'), '$.user_id').alias('extracted_user_id'))