[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: List of differences between XML and JSON?
Hi Hans, > you write: "JSON is typically used to express a set of objects and the connections (links/edges) > between them, without restricting how many links point to the same object. > This makes JSON convenient for expressing directed graphs." > > Could you explain? I hope that it wouldn't be necessary to provide a picture of the JSON object graph, and that this simple example would be easy to understand: {"20thCentury" :[ {"title" : "To Kill a Mocking Bird", "author" : "Harper Lee", "year" : 1960},
{"title" : "The Lord of the Rings", "author" : "Tolkien", "year" : 1954},
{"title" : "The Giver", "author" : "Lois Lowry", "year" : 1993} ],
"90s" : [ {"title" : "The Giver", "author" : "Lois Lowry", "year" : 1993},
{"title" : "American Psycho", "author" : "Bret Easton Ellis", "year" : 1960},
{"title" : "The Notebook", "author" : "Nicholas Sparks", "year" : 1996} ] } This JSON object represents a set of two (named/labeled properties) small listings (collections) of famous books. The name-of /label-to each property is "20thCentury" and "90s". Each of these two collections is a JSON object itself, and the name/label that it is referred to from the outermost object, is not part of the collection object. The labels serve as links/references from the referencing to the referenced objects. The collection object doesn't know that it is referred to in another object and labeled as "90s". In fact, the same collection object could be referred to by another object using a completely different label, say: "John’s favorites" and thus shared between these two objects. Each collection object is an array of other JSON objects, each of which represents a book, and each such object has properties (labels) named "title", "author" and "year". The values to which this labels refer are not themselves JSON objects (may be thought of as leaf nodes in a graph, or terminal (literal) symbols in a grammar) None of the book objects inside of the collection objects knows that it is used in an array and that it has particular "neighbors" in particular order. Now, notice that the book object representing "The Giver" by Lois Lowry, takes part in both collections. This is another example how two different JSON objects share a single third JSON object. One could argue that these are two different JSON objects that happen to represent the same book. This is not true, because these "two objects" cannot have their own different data and if we want to change, for example, the year when the book was written, we must make the change in both of these "two objects". To summarize: this example shows:
Note: 1. I am not aware of any formal definition of JSON object graphs and object sharing. The example above is based on my own experience with and observation of real-world usage of JSON. I think that for any specific directed acyclic graph, a JSON object (in fact infinite number of JSON objects) that have the same topology exists. A JSON object that refers to N other JSON objects is represented in its corresponding graph as a node that has N outgoing arcs/edges. A JSON object that is referred to (labeled from) M other JSON objects is represented in the graph as a node with M incoming arcs/edges. 2. As mentioned in previous messages, one can easily give a similar example with XPath 3.0 maps (together with arrays/sequences) , and I think that a number of other PL types, such as Python and C# dictionaries have similar properties. Cheers, Dimitre Novatchev On Sat, May 2, 2015 at 3:17 PM, Hans-Juergen Rennau <hrennau@yahoo.de> wrote:
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] |
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|