JSON

<empiricists>
  <name>
    <first>David</first>
    <last>Hume</last>
  </name>
  <name>
    <first>John</first>
    <last>Locke</last>
  </name>
  <name>
    <first>George</first>
    <last>Berkeley</last>
  </name>
</empiricists>


{"empiricists":
  [
    {"name": {
      "first": "David",
      "last": "Hume"
    }},
    {"name": {
      "first": "John",
      "last": "Locke"
    }},
    {"name": {
      "first": "George",
      "last": "Berkeley"
    }},
  ]
}


There are two basic data structures used in the above example:
  • Arrays: These are denoted by square brackets, and contain a list of items separated by commas. For example: ["a","b","c"].
  • Objects: These contain key/value pairs. Objects, in this case, work like dictionaries, maps, and associative arrays. These are denoted by curly braces and lists of colon-separated pairs individuated by commas. For example: {"key 1": "value 1", "key 2": "value 2" }.

Since JSON matches the JavaScript array and object notation perfectly, instead of parsing the contents with a sophisticated parse, the JavaScript eval() function can be used instead.










Comments