Send
Close Add comments:
(status displays here)
Got it! This site "robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website. Note: This appears on each machine/browser from which this site is accessed.
JSON
1. JSON
JSON (JavaScript Object Notation) is a common way to represent data for storage, retrieval, transmission, etc.
JSON was developed by
Douglas Crockford (JSON creator and JavaScript evangelist) from the way in which JavaScript represents data.
2. XML
Another (historical) popular data exchange format, still in use today, is
XML (Extensible Markup Language) (left as a future topic).
In general, JSON is less verbose, less complex, and somewhat easier to work with than XML.
Most computer languages support JSON. Of course, since JSON is based on JavaScript data representation, JSON is essentially built into JavaScript.
3. JavaScript data
JavaScript data, as used in JSON, includes the following.
numbers, strings, booleans (true or false), null
lists (called arrays)
dictionaries (called objects)
Note that there is only one number type in JavaScript, the floating point data type. But JSON supports integers and that data type might be used in other languages.
Almost every programming language has some way or library with which to read and write JSON.
4. Convention used here
To avoid confusion with other programming languages and concepts, the following naming conventions are used.
What JavaScript/JSON calls an array will be called a list.
What JavaScript/JSON calls an object will be called a dict or dictionary. This is sometimes called a hash table.
5. Terminal types
Terminal types are types "at the end of the line" and that are considered atomic.
The JSON terminal types are numbers, strings, booleans (true or false), null.
6. Syntax diagrams
That is, a Terminal is a Number or a String or a Boolean or a Null.
7. Grammar rules
Terminal = "Number" | "String" | "Boolean" | "Null" .
8. JSON lists
Lists, called arrays in JavaScript, allow a sequence of elements to be represented.
Here is a JSON list of 5 elements.
[2, 3, 5, 7, 11]
Note: Many languages allow a comma after the last element, but not JSON. Newer JavaScript systems allow that comma.
9. Syntax diagrams
That is, a List is a left square bracket followed by zero or more elements, separated by a comma, and followed by a right square bracket.
For defining an Element, the
dict structure is covered (below).
10. Grammar rules
List = "[" [ Element { "," Element } ] "]" .
11. JSON dicts
A
dict consists of a name-value pair where the name is a String and the value in an Element.
Here is a JSON dict of three name-value pairs.
{
"red" : "FF0000",
"green" : "00FF00",
"blue" : "0000FF"
}
Note: Many languages allow a comma after the last element, but not JSON. Newer JavaScript systems allow that comma.
12. Syntax diagrams
13. Grammar rules
Dict = "{" [ Pair { "," Pair } ] "}" .
Pair = "String" ":" Element .
14. Elements
That is, an Element is a Terminal or a List or a Dict, where each is defined using the previous rules.
15. Grammar rules
Element = Terminal | List | Dict .
16. End of page