EXERCISING JSON
JSON compact output:
{"Title":"G-WAN Forum users","Pierre":{"created":1310203927,"password":"123","coder":true},"Paul":{"created":1310203927,"password":"456","coder":false}}
JSON formated output (with tabs, spaces, CRs):
{
"Title": "G-WAN Forum users",
"Pierre": {
"created": 1310203927,
"password": "123",
"coder": true
},
"Paul": {
"created": 1310203927,
"password": "456",
"coder": false
}
}
Searching, Querying and Updating Paul:
Does Paul exist: yes
Paul's password: 456
New password: abc
Account created: Sat Jul 9 11:32:07 2011
Removed Pierre, Paul and Title:
{
}
Adding Pierre again.
Adding IDs[], an array of items to Pierre:
{
"Pierre": {
"created": 1310203927,
"password": "123",
"coder": true,
"IDs": [ 1.0002, -23.4, 345, -4578 ]
}
}
Get IDs[i] by its array index value:
IDs[ 2] = 345.000000
IDs[200] not found
Update IDs[i]'s NUMERIC value:
IDs[2] = 777.000000
Update IDs[i]'s NUMERIC value directly:
IDs[2] = -88.800000
Adding an array of nodes (Jack, Tom, Kate):
{
"Pierre": {
"created": 1310203927,
"password": "123",
"coder": true,
"IDs": [ 1.0002, -23.4, -88.8, -4578 ]
},
"staff": [ {
"name": "Jack",
"created": 1310203927,
"password": "qve",
"coder": false
}, {
"name": "Tom",
"created": 1310203927,
"password": "smt",
"coder": true
}, {
"name": "Kate",
"created": 1310203927,
"password": "fix",
"coder": true
} ]
}
Searching item 'KATE' by its value:
Kate found: Kate's password: 'fix'
Finding 'Kate' (the parent node) from its (child) 'password' node:
user found: 'Kate'
Clear tree, rebuild it from text and parse it:
Parsing worked.
JSON compact output:
{"Pierre":{"created":1310203927,"password":"123","coder":true,"IDs":[1.0002,-23.4,-88.8,-4578]},"staff":[{"name":"Jack","created":1310203927,"password":"qve","coder":false},{"name":"Tom","created":1310203927,"password":"smt","coder":true},{"name":"Kate","created":1310203927,"password":"fix","coder":true}]}
JSON formated output (with tabs, spaces, CRs):
{
"Pierre": {
"created": 1310203927,
"password": "123",
"coder": true,
"IDs": [ 1.0002, -23.4, -88.8, -4578 ]
},
"staff": [ {
"name": "Jack",
"created": 1310203927,
"password": "qve",
"coder": false
}, {
"name": "Tom",
"created": 1310203927,
"password": "smt",
"coder": true
}, {
"name": "Kate",
"created": 1310203927,
"password": "fix",
"coder": true
} ]
}
Traversing our JSON tree:
o Type: NODE Name: Pierre Value: N/A
oo Type: NUMBER Name: created Value: 1310203927.000000
oo Type: STRING Name: password Value: 123
oo Type: TRUE Name: coder Value: N/A
oo Type: ARRAY Name: IDs Value: N/A
ooo Type: NUMBER Name: (null) Value: 1.000200
ooo Type: NUMBER Name: (null) Value: -23.400000
ooo Type: NUMBER Name: (null) Value: -88.800000
ooo Type: NUMBER Name: (null) Value: -4578.000000
ooo (null)
oo (null)
o Type: ARRAY Name: staff Value: N/A
oo Type: NODE Name: (null) Value: N/A
ooo Type: STRING Name: name Value: Jack
ooo Type: NUMBER Name: created Value: 1310203927.000000
ooo Type: STRING Name: password Value: qve
ooo Type: FALSE Name: coder Value: N/A
ooo (null)
oo Type: NODE Name: (null) Value: N/A
ooo Type: STRING Name: name Value: Tom
ooo Type: NUMBER Name: created Value: 1310203927.000000
ooo Type: STRING Name: password Value: smt
ooo Type: TRUE Name: coder Value: N/A
ooo (null)
oo Type: NODE Name: (null) Value: N/A
ooo Type: STRING Name: name Value: Kate
ooo Type: NUMBER Name: created Value: 1310203927.000000
ooo Type: STRING Name: password Value: fix
ooo Type: TRUE Name: coder Value: N/A
ooo (null)
oo (null)
o (null)
Freeing the JSON tree:
Done.