JSON

The wire format you already know

Back in Part I, your iOS app's Codable structs decoded JSON that came over the network โ€” {"id": 3, "name": "Rex"} turning into a Swift struct. That JSON came from a Python backend, and Python's json module is the other half of that same conversion.

Two functions, two directions:

  • json.loads(text) โ€” parse a JSON string into a Python dict (loads = load from a string).
  • json.dumps(data) โ€” convert a Python dict back into a JSON string (dumps = dump to a string).