JSON round-trips in Python
Serializing to JSON text and parsing it back.
import json
profile = {
"name": "ada",
"langs": ["python", "rust"],
"active": True,
"streak": 7,
}
text = json.dumps(profile, indent=2, sort_keys=True)
restored = json.loads(text)
compact = json.dumps(profile, separators=(",", ":"))
langs = restored["langs"]
same = restored == profile
How it works
dumpsrenders a dict as text, with options.loadsparses text back into Python objects.- The restored value equals the original.
The run, in numbers
- Lines
- 15
- Characters to type
- 288
- Tokens
- 97
- Three-star pace
- 100 tpm
At the three-star pace of 100 tokens a minute, this run takes about 58 seconds.
Step 1 of 5 in Data formats, step 17 of 41 in Domain tools.