JSON Cheat Sheet

A Programming › JavaScript cheat sheet in English by Gaston
41,565 views 6,643 downloads 21 Oct 2015 History
4.6 avg · 2 ratings

Overview example

{  "sequence": 52634, 
   "employees" : [
      { "first": "Anna", "last:": "Smith", "loc": 1},
      { "first": "John", "last:": "Doe", "loc" : 1 },
      { "first": "Sandra", "last:": "Jones", "loc" : 2} 
    ],
    "locations" : [
      { "city" : "New York", "type" : "HQ", key: 1 },
      { "city" : "Los Angeles", "type" : "Branch", key: 2 }
    ]
}
  
This is a virtual example demons­trating JSON usage. The main object contains a sequence number ("se­que­nce­") with a value of 52634, an array of employees and an array of locations.

Values

"­str­ing­"
see "­Str­ing­s" box for details
1234
integer number
1234.5678
floating point number
1.234e-3
floating point with exponent(1)
true
boolean "­Tru­e"
false
boolean "­Fal­se"
null
denoting "­emp­y"
object
a value can be an object
array
a value can be an array of values
(1) Exponent prefix is case insens­itive (e or E) and could be followed by a sign, mandatory for negative, optional for positive

Object

{ }
empty object
{ "­key­" : value }
single value object
{ "­key­1" : value , "­key­2": value, ... }
multiple value object
(1) An object is the preferred top level structure for JSON
(2) The key can be any string (see "­str­ing­" for details)
(3) See "­Val­ues­" box for inform­ation on possible values

Array

[ ]
empty array
[ value ]
single element array
[ value , value , ... ]
multiple value array
(1) See "­Val­ues­" box for inform­ation on possible values

Strings

"­"
empty string
"some string charac­ter­s"
string(1)
(1) see "­String charac­ter­s" box for details on allowed characters and coding

String character

non-sp­ecial characters
Any unicode character except " (quotes), \ (backs­lash) or any control character
\"
double quotes
\\
backslash
\/
slash
\b
backspace
\f
formfeed
\n
newlinw
\r
carriage return
\t
horizontal tab
\uXXXX
where XXXX is the 4 digit hexade­cimal unicode code for the character

Badges

Useful Cheat Sheet Nice Cheat Sheet Good Cheat Sheet Downloaded from Unusual Locations × 4

Comments (1)

jimchen0168 20:13 12 Jun 2018

good

Reply

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.