Show Menu
Cheatography

JavaScript Object Notation (json) Cheat Sheet (DRAFT) by

JSON Cheatsheet by Emre Coltu, Free University Berlin

This is a draft cheat sheet. It is a work in progress and is not finished yet.

General Inform­ation

• Data is in key/value pairs
• Data groups by colon "­:­" and separates by comma "­,­"
• Objects are surrounded with curly braces "{" and "}"
• Each key in objects should be unique
• Arrays are surrounded with square brackets "[" and "]"
• Light, human-­rea­dable data-i­nte­rchange format
• Can be used with modern progra­mming languages
• Language indepe­ndent
• The trailing commas and leading zeros are prohibited
• Numbers can't have octal or hexade­cimal format
Easy to use and doesn't use full markup like XML
• Popular due to it's asynch­ronous speed
• Extension for Json files is ".json"
• Mime type for Json texts is "applic­ati­on/json"
• Official media type for Json is "applic­ati­on/json"
• Json internet media type is "applic­ati­on/json"
• The uniform type identifier for Json is "public.json"

Data Types

Json
Python
Possible Values
boolean
bool
true | false
number
float
123 | 123.456 | 1234e-3
string
str
"abcdef" | "­"
array
list
["a", "­b", "­c", "­d"]
object
dict
{"id": 7}
null
None
null

Escape Sequences

Name
Sequence
Double Quote
\"
Backslash
\\
Slash
\/
Backspace (BS)
\b
Form Feed (FF)
\f
Horizontal Tab (HT)
\t
Newline (NL)
\n
Carriage Return (CR)
\r
Hexadecimal
\uXXXX

Arrays

Syntax
Descri­ption
arr = []
Empty Array
arr = ["Ja­mes­"]
Single Element Array
arr = [
    "James",
    "Bond",
    42,
    "M",
    {"Germany": "­Ber­lin­"},
    true
]
Multi Element Array
Firstname
Lastname
Age
Sex
Location
Available

Objects

Syntax
Descri­ption
obj = {}
Empty Object
obj = {"ke­y": value}
Single Element Object
obj = {
    "Firstname": "­Jan­e",
    "Lastname": "­Doe­",
    "Age": 39,
    "Sex": "­F",
    "Location": {"DE­": "­Ber­lin­"},
    "Availability": false
}
Multi Element Object
Firstname
Lastname
Age
Sex
Location
Availability

Nested Object and Arrays

nested = {
    "indexes": {
        "Firstname": 0,
        "Lastname": 1,
        "Age": 2,
        "Sex": 3,
        "Country": 4,
        "Available": 5
    },
    "user": [
        "James",
        "Bond",
        42,
        "M",
        {"Germany": "­Ber­lin­"},
        true
    ]
}

Nested Objects and Arrays

nested = {
 ­ ­ ­ ­"­def­aul­ts": {
 ­ ­ ­ ­ ­ ­ ­ ­"­Fir­st": 0,
 ­ ­ ­ ­ ­ ­ ­ ­"­Las­t": 1,
 ­ ­ ­ ­ ­ ­ ­ ­"­Age­": 2,
 ­ ­ ­ ­ ­ ­ ­ ­"­Sex­": 3,
 ­ ­ ­ ­ ­ ­ ­ ­"­Cou­ntr­y": 4,
 ­ ­ ­ ­ ­ ­ ­ ­"­Ava­ila­ble­": 5
 ­ ­ ­ },
 ­ ­ ­ ­"­hus­ban­d": [
 ­ ­ ­ ­ ­ ­ ­ ­"­Jam­es",
 ­ ­ ­ ­ ­ ­ ­ ­"­Bon­d",
 ­ ­ ­ ­ ­ ­ ­ ­"­42",
 ­ ­ ­ ­ ­ ­ ­ ­"­T",
 ­ ­ ­ ­ ­ ­ ­ ­"­Ger­man­y",
 ­ ­ ­ ­ ­ ­ ­ true
 ­ ­ ­ ],
 ­ ­ ­ ­"­wif­e": [
 ­ ­ ­ ­ ­ ­ ­ ­"­Jan­e",
 ­ ­ ­ ­ ­ ­ ­ ­"­Hon­da",
 ­ ­ ­ ­ ­ ­ ­ ­"­42",
 ­ ­ ­ ­ ­ ­ ­ ­"­T",
 ­ ­ ­ ­ ­ ­ ­ ­"­Ger­man­y",
 ­ ­ ­ ­ ­ ­ ­ ­false
 ­ ­ ­ ]
}

Arrays

array = []
Empty Array
array = ["Ja­mes­"]
Single Element Array
array = [
Multi Element Array
 ­ ­ ­ ­"­Jam­es",
 ­ ­ ­ ­"­Bon­d",
 ­ ­ ­ ­"­42",
 ­ ­ ­ ­"­T",
 ­ ­ ­ ­"­Ger­man­y",
 ­ ­ ­ true
]

Objects

myobject = {}
Empty Object
myobject = {"ke­y": value}
Single Element Object
myobject = {
Multi Element Object
 ­ ­ ­ ­"­Fir­st": "­Jam­es",
 ­ ­ ­ ­"­Las­t": "­Bon­d",
 ­ ­ ­ ­"­Age­": "­42",
 ­ ­ ­ ­"­Sex­": "­T",
 ­ ­ ­ ­"­Cou­ntr­y": "­Ger­man­y",
 ­ ­ ­ ­"­Ava­ila­ble­": true
}

Syntax
Descri­ption
arr = []
Empty Array
arr = ["Us­ern­ame­"]
Single Element Array
arr = [
    "James",
    "Bond",
    42,
    "M",
    {"Germany": "­Ber­lin­"},
    true
]
Multi Elements Array

Literals

null
true
false

Data Types

boolean
true, false
number
123, 123.456, 1.234e-3
string
"­abc­def­", "­"
array
["a", "­b", "­c", "­d"]
object
{"id­": 7}
null
null

General Inform­ation

• Doesn't have comments. Everything in it is considered data
• Data is in name/value pairs. Grouped by a colon "­­:" and separated by comma "­­,"
• Objects are surrounded with curly braces. Each key within should be unique and enclosed within the double quotes. An object begins with a left brace "­{" and ends with a right brace "­}"
• Arrays are surrounded with square brackets. An array begins with a left bracket "­[" and ends with a right bracket "­]"
• The trailing commas and leading zeros are prohibited
• Numbers can't have octal or hexade­cimal format
• Lightw­eight and human-­rea­dable data-i­nte­rchange format
• Can be used with modern progra­mming languages
• Language indepe­ndent
• Very easy to parse and generate and doesn’t use a full markup structure like a XML
• Popular altern­ative to XML format for its fast asynch­ronous client­–server commun­ication
• Extension for json files is ".js­on"
• Mime type for json texts is "­app­lic­ati­on/­jso­n"
• The official media type for json is "­app­lic­ati­on/­jso­n".
• json internet media type is "­app­lic­ati­on/­jso­n".
• The uniform type identifier is "­pub­lic.js­on"

Escape Sequences

Double Quote
\"
Backslash
\\
Slash
\/
Backspace (BS)
\b
Form Feed (FF)
\f
Horizontal Tab (HT)
\t
Newline ()
\n
Carriage Return
\r
Hexade­cimal
\uXXXX