Examples of a same message written in XML & JSON




 XML is short for Extensible Markup Language. 
JSON is short for JavaScript Object Notation.

Message can be written in both XML and JSON . There're examples of the same message("menu") in XML and JSON:

The text expressed as XML:

<menu id="file" value="File">
  <popup>
    <menuitem value="New" onclick="CreateNewDoc()" />
    <menuitem value="Open" onclick="OpenDoc()" />
    <menuitem value="Close" onclick="CloseDoc()" />
  </popup>
</menu>


The same text expressed as JSON:
{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
    ]
  }
}}

After learnt about XML, reading the above examples helped me understand JSON!



0 comments:

Post a Comment