This makes sense, given that the format is used for
interchange rather than programming that should concern itself with memory.
number
digit
digit
digit
1??“9
??’
+
??’
0 .
e
E
digit
134 Par t I : C o r e I d e a s
Legal JSON number values have quite a range of forms, just as they do in JavaScript:
3
-1968
200001
- 0.9
3333.409
3e+1
4E-2
-0.45E+10
Arrays are just as they would be in JavaScript when containing only literals, a list of
values separated by commas:
array
[ ] value
,
An example of arrays in JSON follows:
["Larry", "Curly", "Moe", 3, false]
JSON objects are similar to the object literal format found in JavaScript except that the
properties will always be strings rather than identifiers:
object
{ } string value
,
:
For example:
{"firstname": "Thomas", "lastname" : "Powell" , "author" : true,
"favoriteNumber" : 3 , "freeTime" : null}
JSON values can nest, thus the following more complex examples are legal JSON structures:
[ {"name" : "Larry" , "hair" : true },
{"name" : "Curly" , "hair" : false },
{"name" : "Moe" , "hair" : true }
]
{ "primaryStoogeNames" : ["Larry", "Curly", "Moe"],
"numberofStooges" : 3,
"alternateStooges" : [ {"name" : "Shemp", "original" : true } ,
{"name" : "Joe", "original" : false } ,
{"name" : "Curly Joe", "original" : false }
]
}
C h a p t e r 4 : D a t a F o r m a t s 135
PART I
As seen in the previous, more complex JSON examples, white space can be used
liberally and will add in readability if you expect human inspection.
Pages:
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213