The JSON format was inspired by the object and array format used in the JavaScript language. But since Python was invented before JavaScript, Python's syntax for dictionaries and lists influenced the syntax of JSON. So the format of JSON is nearly identical to a combination of Python lists and dictionaries.
Here is a JSON encoding of some data. The outermost JSON structure is a dictionary and the value for two of the keys (phone and email) are dictionaries as well.
You will notice some differences. First, in XML, we can add attributes like “intl” to the “phone” tag. In JSON, we simply have key-value pairs in a dictionary. Also the XML “person” tag is gone, replaced by a set of outer curly braces.
In general, JSON structures are simpler than XML because JSON has fewer capabilities than XML. But JSON has the advantage that it maps directly to some combination of dictionaries and lists. And since nearly all programming languages have something equivalent to Python's dictionaries and lists, JSON is a very natural format to have two cooperating programs exchange data.
1.
csp-10-2-1: Which of the following are differences between JSON and XML?
XML uses attribute = "value" and JSON uses "attribute" = "value"
Correct! XML uses attribute = "value" and JSON uses "attribute" = "value"
XML supports nested data, but JSON does not
Incorrect. Both support nested data
XML is used to structure data, and JSON is not
Incorrect. Both are used to structure data
XML is extensible, while JSON is not
Correct! XML is extensible and JSON is not.
2.
csp-10-2-2: Which of the following is not a difference between JSON and XML?
XML can add attributes to tags.
XML can add attributes to tags, while JSON uses key-value pairs.
JSON uses curly braces.
JSON uses curly braces in place of some tags used in XML.
XML has a simpler structure than JSON.
XML is actually a more complex than JSON because it has more capabilities.
JSON has a simpler structure than XML.
JSON has a simpler structure than XML and fewer capabilities.
JSON is quickly becoming the format of choice for nearly all data exchange between applications because of its relative simplicity compared to XML.
3.
csp-10-2-3: JSON stands for what?
Java Single Object Notation
JSON uses some Java notations but isn't fully in the acronym.
JavaScript Object Notation
JSON is an acronym for JavaScript Object Notation.
JavaScript Server Operation Notation
The "s" in JSON is actually included in the first word!
Java Sold On Nantucket
Java (coffee) is sold many places.
List of Dictionaries
The outermost JSON structure can be a dictionary or a list. Here is an example where the outermost JSON structure is a list. In this case it is a list of dictionaries.