Premier IT Outsourcing and Support Services within the UK

User Tools

Site Tools


JSON (Javascript Object Notation)

While the format was first developed in the early 2000s, the first standards were published in 2006. Understanding what JSON is and how it works is a foundational skill for any IT power user.

JSON is a human-readable format for storing and transmitting data. As the name implies, it was originally developed for JavaScript, but can be used in any language and is very popular in web applications. The basic structure is built from one or more keys and values:

  1. {
  2. "key": value
  3. }

You’ll often see a collection of key:value pairs enclosed in brackets described as a JSON object. While the key is any string, the value can be a string, number, array, additional object, or the literals, false, true and null. For example, the following is valid JSON:

  1. {
  2. "key": "String",
  3. "Number": 1,
  4. "array": [1,2,3],
  5. "nested": {
  6. "literals": true
  7. }
  8. }

JSON doesn’t have to have only key:value pairs; the specification allows for a list or array which is enclosed in square braces such as:

  1. ["red","green","blue"]

The square braces indicate an array or list, in this case {"red","green","blue"} is invalid because the { } indicate a key/value pair, but [ ] indicate a list or array. You can have a list as a value as shown in the example two above.

To be valid, there must be a matching set of } for every { and ] for every [ , and elements must be comma separated and types must be correctly quoted.

  1. {
  2. "Name":"Kevin",
  3. "Age":15
  4. "Password":monkey,

Is NOT VALID, there's no comma after 15 on the second line, an extra comma after monkey, monkey is not "Quoted" and as a string it should be and its missing the trailing }. JSON processors do forgive some simple errors like leaving the last , in an element even though there aren't any more but this cannot be relied upon and some are more strict than others. Keep it valid and everything will always work.

/data/webs/external/dokuwiki/data/pages/computerfaq/json.txt · Last modified: 2023/01/06 07:54 by genadmin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki