Skip to content

Brainstorming JSON Serialization

Jim Fulton edited this page Oct 22, 2016 · 4 revisions

Brainstorming JSON and JSON-like (e.g. msgpack) serialization

Amongst the challenges:

  • Expressing class
  • Expressing persistent references.
  • Expressing cycles

Some ideas I've thought about.

  • For class, oid, and serial, use regular names.
  • References are object with a single "->" property, who's value identifies the object being referenced.
    • Integer ids are internal references.
    • Other ids are external/persistent references.
  • When an object is referenced multiple times internally, it's wrapped in an object with properties __shared_id__, with an integer value assigning the id, and __shared_value__ who's value is the shared data,

In this example:

   {"__class__": "somemodule.Foo",
    "_p_oid": "1231ab",
    "_p_serial": "1234567890abcd",
    "x": 1,
    "parent": {"->": "1231aa"},
    "y": {"__shared_id__: 0, "__shared_value__": ["a", 3, {"->": 0}]
    }

parent
  A regular property who's value is a persistent reference.

y
  A regular property with a shared list that refers to itself,
Clone this wiki locally