5

Whenever someone here says "I have a JSON object", people complain (rightly) that "There's no such thing as a JSON object!" But...

What do you call the class of data structures that could be represented by JSON?

It's something like "the finite transitive closure of Map, List, Number, String, and Boolean" -- that is, omitting things like functions and the fancier structures like sets and queues. The category is useful. Obviously, everything done in JSON uses it. CouchDB (and I think the other document-oriented databases) use it. Most acyclic data structures are contained in it.

But what it is called?

Michael Lorton
  • 43,060
  • 26
  • 103
  • 144
  • 1
    json stands for javascript object notation so any object is json and any json is an object. but when you are outside javascript we refer to this type of object as json because the format is derived from a javascript object – Ibu Aug 27 '11 at 00:35
  • @Ibu "Any object is JSON", not completely true, JSON uses a sub-set of JS syntax, not everything that can be done with a JS object can be represented with JSON. For instance JS objects can have functions as values (methods) those can't be exported to JSON. Also JSON requires property names in objects be quoted, JS does not, JSON requires double quotes, JS can use double or single: `{validJS: 'but not valid JSON'}`. A JSON string is however valid JS: `{"validJS": "and also valid JSON"}`. – Useless Code Jun 25 '15 at 02:43
  • I really wish that Mr Crockford had *not* used the term "JSON", because by including "JS" for JavaScript this has caused endless confusion over the years. Not sure what a better term might have been - maybe "GON" or "OSF" for "generic object notation" or "object serialisation format"? Whatever, too late now. – nnnnnn Sep 04 '16 at 03:18
  • In this RFC, Mr Crockford called them [JSON objects and JSON arrays](https://tools.ietf.org/html/rfc4627#page-7) – James Jun 27 '17 at 16:57

4 Answers4

3

JSON is simply a notation that happens to easily translate to Javascript objects. When JSON is reified in Javascript (evaluated), it turns into a Javascript object/associative array (depending on the JSON representing it).

I think the class of data structures that can be represented by JSON are just that: "data structures". For example, you could represent binary trees in JSON, or even lists and maps; these are specific data-structures in their own right, and the overall term for them is just "data structure".

Assuming that JSON could only represent one specific type of data structure (for example, only trees), then we could call the class of objects represented by JSON as just "trees". But JSON does more than that; it can represent different kinds of data structures, which is why it's probably just best to say "I have this JSON here and it represents the so-and-so data-structure".

I guess if you really boil it down, JSON represents a data-structure that is either a sequence or a structure that contains name-value pairs, where the values can be primitives (ints, strings, floats, booleans, nulls, undefineds), or name-value pairs or sequences.

Thinking about it a bit more, asking for the name of the class of data structure that could be represented by JSON is like asking for the name of the class of data structures that could be represented by XML. Both are abstract notations that can be reified into actual objects.

TL; DR; Just call it an object, or by its actual data-structure name. It's just like saying "XML Object". There's no general name for the class of structures represented by XML. XML can represent an object, just like JSON can represent an object.

Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
2

You could call them "JSON-compatible" or "JSON-serializable" maybe.

Matthew Crumley
  • 101,441
  • 24
  • 103
  • 129
0

I think the question is a little leading since any object could be represented in JSON if you overrode the serialization on the object.

Now if you mean, what objects could natively be represented as JSON, that depends on your language and environment.

davecoulter
  • 1,806
  • 13
  • 15
  • Not *any* object. It would be impossible to represent any cyclical data-structure in JSON since you cannot self-reference. – Vivin Paliath Aug 27 '11 at 00:46
  • @Vivin: You *can* represent cyclical structures, you just have to convert it to a non-cyclical structure and have some kind of convention for converting it back. – Matthew Crumley Aug 27 '11 at 00:56
  • @Matthew Crumley -- exactly. It seems JSON is more of a serialization convention to work with Javascript, rather than something fundamental to a given class of datastructures. – davecoulter Aug 27 '11 at 01:03
  • @Matthew You're correct, but I was thinking in terms of a direct translation, without conversion. davecoulter That's pretty much what I think as well. It's more of a notation/representation/convention. So it's an abstract concept. – Vivin Paliath Aug 27 '11 at 01:11
  • @Vivin: Yeah, for the purposes of the question, I wouldn't consider cyclical structures "JSON compatible" (which, now that I think of it, might be a good answer), I just thought I'd mention that it's possible since I actually just did something similar recently. – Matthew Crumley Aug 27 '11 at 15:13
  • @Matthew I had flashbacks to my data structures class: converting cyclical graphs :) – Vivin Paliath Aug 27 '11 at 17:19
  • You can't really represent a JS function in JSON - you can, of course, represent its source as a string, but at runtime a function has context: how would you serialise a closure? – nnnnnn Sep 04 '16 at 03:16
0

Is there a JSON object? Nope. Doesn't it take on the object type that it is serialized to? As above

If JSON is a data interchange format and the resulting files in JSON format follow the specification, doesn't it track that you have an array of or a list of items, not objects?

John Stack
  • 618
  • 1
  • 4
  • 19