Lesson 7.10
JSON is a text format for data. The json module turns a dictionary into a string and
back:
import json
profile = {"name": "Mia", "age": 14}
text = json.dumps(profile, ensure_ascii=False)
print(text)
back = json.loads(text)
print(back["name"])
dumps goes from a dictionary to a string; loads goes from a string back to a
dictionary;ensure_ascii=False keeps non-English letters as they are, without \u0430;indent=2 produces pretty output with indentation.The check sets the name name and the age age. Build the dictionary profile, turn it
into text with dumps using ensure_ascii=False and indent=2, print the text, then run
loads on that text and print the name from the result.
json.dumps goes from a dictionary to text, json.loads goes from text back to a
dictionary.
For pretty output add indent=2 and ensure_ascii=False, so letters don't turn into
\u.... Read back the text.