0

Originally, JSON borrowed its syntax from JavaScript (object literals), but then became a programming language agnostic data interchange format. Its structures (string, array, object) can be mapped directly to primitive data types in most dynamic programming languages and vice versa.

Now, since it is no longer tied to JavaScript, what is the abstract data model of JSON today? In other words, if we compare XML with JSON, is there a XML Infoset equivalent for JSON?

Obviously, JSON is not the only format that can be used for serialization of JSON-like documents. Alternatives include YAML, BSON, and even XML. Is there a name for that unified data model and perhaps a formal specification available?

proskor
  • 1,382
  • 9
  • 21
  • In YAML you are probably looking for the [JSON Schema](http://www.yaml.org/spec/1.2/spec.html#id2803231), which defines the intpretation of scalars so that compatibility with JSON is established. – Anthon May 28 '17 at 18:13

1 Answers1

0

XML is more complicated that JSON format. Some common features that XML has and JSON lacks are: namespaces, attributes, comments. However, both formats can represent any kind of data, but potentially with a different structure logic.

What's the abstract data model of JSON ? The same as it was when it was created, nothing changed. JSON served as a data format for server-client communication. It was never tied to JavaScript, since it is just a formatted data string and not some kind of binary executable. Its format originates from javascript yes, but any language can interpret it with a text parser.

I am not sure what kind of information you are looking for, but the name of the process that converts language-specific structured data into strings and vise versa is called Serialization/Unserialization, but you already know these terms ...

"Unified data model", "formal specification", what are you even looking for ? Are you looking for principles of data formatting ? Data storing ? People need to store/transmit/present their data and they come up with ways to do it, there is nothing more to it.

George Dimitriadis
  • 1,681
  • 1
  • 18
  • 27
  • What I am looking for is really simple. JSON is basically just a concrete syntax for encoding data consisting of strings, lists, dicts and so on. The same holds for YAML and BSON. Therefore it is possible to define a direct 1-to-1 mapping from JSON to JAML, for example. Then, although the two documents (one in JSON and another in YAML) would be syntactically different (they would require different parsers to read them, for example), their structures would be identical, they would conform to the same data model. The question is: is this data model specified somewhere? – proskor May 28 '17 at 16:59
  • @proskor The same doesn't hold for YAML, there are constructs that you can save (and re-load) in YAML that cannot be saved using JSON without JSON needing a program that semantically interprets the primitives. Recursive and self-recursive structures are a prime example of this. There is a 1-to-1 mapping from JSON to YAML, as a YAML (1.2) parser can read JSON, but there is no such mapping from YAML to JSON (or from XML to JSON). – Anthon May 28 '17 at 18:10
  • @Anthon So the YAML model is strictly more expressive than JSON? Could you please give an example of a recursive structure in a YAML document? I did not know that was possible, but I would like to learn. – proskor May 29 '17 at 05:42
  • @proskor YAML 1.2 is for all real purposes a superset of JSON. Look for the anchors and aliases in the YAML documentation. This [answer](https://stackoverflow.com/questions/41900782/why-does-pyyaml-use-generators-to-construct-objects/41900996#41900996) has some examples. – Anthon May 29 '17 at 10:05
  • Additionally, in YAML [any object can be used as a mapping key](https://stackoverflow.com/questions/33987316/what-is-a-complex-mapping-key-in-yaml), whereas in JSON only strings can be used as keys. – Jordan Running Jun 01 '17 at 20:28