JSON and XML
JSON and XML are two technologies used to transfer data between applications.
JSON
JSON stands for JavaScript Object Notation, and is an open standard, more readable than XML but can sometimes be limited, especially in terms of describing structure and allowing for searching.
JSON is thus simpler, and can be better to use in a number of occasions. For example, when sending data or retrieving data from a Web API where the size of the request and the response are impactful.
Here is a (slightly biased) comparison of JSON and XML: http://www.json.org/xml.html.
A less biased one is here.
Below, a possible JSON representation describing a person:
{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
],
"children": [],
"spouse": null
}
XML
XML stands for eXtensible Markup Language. It is document-oriented and is extensible in the sense that tags can be created and easily re-used. JSON does not need this because it is optimized for data, but XML can in some scenarios be more versatile.
In this course we will not be using XML, but it is worth knowing that it exists, and, to some extent, what it looks like.
The person representation from above, here depicted as XML:
<person>
<firstName>John</firstName>
<lastName>Smith</lastName>
<age>25</age>
<address>
<streetAddress>21 2nd Street</streetAddress>
<city>New York</city>
<state>NY</state>
<postalCode>10021</postalCode>
</address>
<phoneNumbers>
<phoneNumber>
<type>home</type>
<number>212 555-1234</number>
</phoneNumber>
<phoneNumber>
<type>fax</type>
<number>646 555-4567</number>
</phoneNumber>
</phoneNumbers>
<gender>
<type>male</type>
</gender>
</person>
Or it can also be described using tag attributes instead of only tags:
<person firstName="John" lastName="Smith" age="25">
<address streetAddress="21 2nd Street" city="New York" state="NY" postalCode="10021" />
<phoneNumbers>
<phoneNumber type="home" number="212 555-1234"/>
<phoneNumber type="fax" number="646 555-4567"/>
</phoneNumbers>
<gender type="male"/>
</person>
XML looks very much like HTML, which we will be studying in this course.
In fact, HTML also uses tags, attributes, and tags can contain other tags and also literal content, like strings.
HTML stands for HyperText Markup Language, and is used to describe the structure of web-pages (i.e. what is in the page, but not what it looks like).