Challenge - 5 Problems
JSON Reading Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of reading a JSON file with nested objects?
Given the JSON file content:
What will be the output of
{"name": "Alice", "details": {"age": 30, "city": "New York"}}What will be the output of
pd.read_json('file.json')?Data Analysis Python
import pandas as pd from io import StringIO json_data = '{"name": "Alice", "details": {"age": 30, "city": "New York"}}' df = pd.read_json(StringIO(json_data), typ='series') print(df)
Attempts:
2 left
💡 Hint
Think about how pandas handles nested JSON objects by default.
✗ Incorrect
Pandas reads the JSON and creates columns for top-level keys. Nested objects become entries in cells as dictionaries, not automatically flattened.
❓ data_output
intermediate1:30remaining
How many rows are in the DataFrame after reading a JSON array?
Given this JSON array:
What is the number of rows in the DataFrame after
[{"id": 1, "score": 88}, {"id": 2, "score": 92}, {"id": 3, "score": 75}]What is the number of rows in the DataFrame after
pd.read_json()?Data Analysis Python
import pandas as pd from io import StringIO json_data = '[{"id": 1, "score": 88}, {"id": 2, "score": 92}, {"id": 3, "score": 75}]' df = pd.read_json(StringIO(json_data)) print(len(df))
Attempts:
2 left
💡 Hint
Each object in the JSON array becomes one row.
✗ Incorrect
Each dictionary in the JSON array is converted to one row in the DataFrame, so there are 3 rows.
🔧 Debug
advanced2:00remaining
What error occurs when reading malformed JSON with pd.read_json?
What error will this code raise?
import pandas as pd
from io import StringIO
json_data = '{"name": "Bob", "age": 25,'
df = pd.read_json(StringIO(json_data))Data Analysis Python
import pandas as pd from io import StringIO json_data = '{"name": "Bob", "age": 25,' df = pd.read_json(StringIO(json_data))
Attempts:
2 left
💡 Hint
Look at the JSON string carefully for syntax issues.
✗ Incorrect
The JSON string is incomplete and malformed, causing pandas to raise a ValueError when parsing.
🚀 Application
advanced2:00remaining
How to read a JSON file with multiple JSON objects separated by newlines?
You have a file where each line is a separate JSON object:
Which option correctly reads this file into a DataFrame?
{"id": 1, "val": 10}
{"id": 2, "val": 20}
{"id": 3, "val": 30}Which option correctly reads this file into a DataFrame?
Attempts:
2 left
💡 Hint
Look for the parameter that handles JSON lines format.
✗ Incorrect
The 'lines=True' parameter tells pandas to treat each line as a separate JSON object and combine them into a DataFrame.
🧠 Conceptual
expert1:30remaining
What is the effect of the 'typ' parameter in pd.read_json?
What does setting
typ='series' do when reading JSON with pd.read_json()?Attempts:
2 left
💡 Hint
Think about the difference between Series and DataFrame in pandas.
✗ Incorrect
The 'typ' parameter controls the type of object returned. Setting it to 'series' returns a Series instead of a DataFrame.