tl;dr - I've settled on the terminology
Traversable for the container type which includes
Dict but excludes
Atom for anything which is not traversable, e.g. cannot nest indefinitely. This makes the top-level type signature of
json.loads something like
Union[Traversable, Atom]. I still need to figure out the correct recursive definition, but that's a much more tightly scoped problem.
However, this question has been locked so I cannot add this as an answer.
I'm trying to define the type signature of a bunch of methods which operate on nested containers. Basically, what is the 'shape' of a container which is composed of
lists, as well as primitives (including iterables which cannot nest, such as
str). I can call the latter
Atom, since it cannot be decomposed indefinitely. In other words, what is the common interface of
list? It's not
Iterable, because that includes things like
bytes, and other iterators which aren't containers (like infinite generators).
I am wondering if there is a terminology for the container data structure "isomorphic" to valid JSON, in other words, each item is one of:
- leaf: something really easy to serialize, like a string, number, boolean, or null. Complex data types e.g. images don't count.
JSON is built on two structures:
- A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
- An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
I'm not looking for any particular serialization format, document type, or whatnot. I'm trying to get at "what is the name of the abstract thing which is the union of the two data structures named above".
Constraints: Lists are ordered and indexed by an integer. Objects are unordered and indexed by keys. Leaves/Keys must be strings or have a "stringer interface".
So, anything which could readily implement a
.to_json() interface, e.g.
JSON.stringify (js) or
json.dump (python). But also most Protobuf messages would fit this criteria. If it were just a dict/object, I'd call it a mapping, or if it were just a list/tuple/array, I'd call it that. But this thing is a mixture of lists, dicts, and primitives.
Why? Because I use this interface in my line of work constantly, and I don't have a satisfying name for it. Again, quoting Douglas Crockford:
These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangeable with programming languages also be based on these structures.
Yet we don't have a name for the combined data structure.
I feel like this is a valuable abstraction to talk about, but it'd be inaccurate to call it "a JSON", since it doesn't really have to do with the JSON RFC, that's just a concrete implementation of this thing. Other valid impls are an object in JS, a dict in Python, some kinds of structs in Go, a protobuf message on the wire, a msgpack, etc. Yes you can technically serialize anything, but like, this structure implies not having to call any dedicated serializer on the leaves. A bitmap, a set, a numpy array, etc wouldn't count as valid leaves, without some massaging.
"Nest" perhaps? Naming things is hard.