← Lesson
JSON and Text
Joeven
Run
Reset
Python loads on first run
import json state = { "goal": "fix the test", "steps": 2, "tools": ["read", "run"], "error": None, } text = json.dumps(state, indent=2, sort_keys=True) print(text) loaded = json.loads(text) print("goal", loaded["goal"]) print("error is missing?", loaded["error"] is None) fake_file = json.dumps(state) print("from fake file", json.loads(fake_file)["tools"]) print("JSON likes", json.dumps({"n": 1, "ok": True, "tags": ["a"], "x": None})) print("tuple becomes", json.loads(json.dumps((1, 2)))) line = "atlas,paris,ok" name, city, status = line.split(",") print("csv", name, city, status) rows = ["name,city", "atlas,paris", "bolt,oslo"] for row in rows[1:]: parts = row.split(",") print("row", parts) try: json.loads("{not json") except json.JSONDecodeError: print("decode error as expected")
Run to execute this in your browser. Nothing is sent to a server.