LearnFrenzy
Sign in Take a free test

Modules and Packages · Predict the Output · Question 10

json.dumps and json.loads Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

What is the output of the following Python program?

main.py
import json

s = json.dumps({"b": 1, "a": [True, None]}, sort_keys=True)
print(s)
print(json.loads(s)["a"], type(json.loads("3.0")).__name__)
  • A {'a': [True, None], 'b': 1} [True, None] float
  • B {"b": 1, "a": [true, null]} [true, null] str
  • C {"a": [true, null], "b": 1} [True, None] float Correct
  • D {"a": [true, null], "b": 1} ['true', 'null'] float
Correct Answer: Option C

JSON uses double quotes, true and null; sort_keys orders the keys. loads converts them back to True and None.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links