typestar

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

  1. dumps renders a dict as text, with options.
  2. loads parses text back into Python objects.
  3. 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.

Type this snippet

Step 1 of 5 in Data formats, step 17 of 41 in Domain tools.

← Previous Next →