* Comitted more work, supports encoding and decoding pretty well, although there...
[luajson.git] / test.lua
blobb6bcf193d9623626ad56ae1752a46ed0091227ab
1 -- Additional path that may be required
2 package.path = package.path .. ';?/init.lua'
3 require("json")
5 local testStrings = {
6 [[{1:[1213.3e12, 123 , 123, "hello", [12, 2], {1:true /*test*/}]}]],
7 [[{"username":"demo1","message":null,"password":""}]],
8 [[{"challenge":"b64d-fnNQ6bRZ7CYiNIKwmdHoNgl9JR9MIYtzjBhpQzYXCFrgARt9mNmgUuO7FoODGr1NieT9yTeB2SLztGkvIA4NXmN9Bi27hqx1ybJIQq6S2L-AjQ3VTDClSmCsYFPOm9EMVZDZ0jhBX1fXw3o9VYj1j9KzSY5VCSAzGqYo-cBPY\n.b64","cert":"b64MIIGyjCCBbKgAwIBAgIKFAC1ZgAAAAAUYzANBgkqhkiG9w0BAQUFADBZMRUwEwYKCZImiZPyLGQBGRYFbG9tp8uQuFjWGS_KxTHXz9vkLNFjOoZY2bOwzsdEpshuYSdvX-9bRvHTQcoMNz8Q9nXG1aMl5x1nbV5byQNTCJlz4gzMJeNfeKGcipdCj7B6e_VpF-n2P-dFZizUHjxMksCVZ3nTr51x3Uw\n.b64","key":"D79B30BA7954DF520B44897A6FF58919"}]],
9 [[{"key":"D79B30BA7954DF520B44897A6FF58919"}]],
10 [[{"val":undefined}]],
11 [[{
12 "Image": {
13 "Width": 800,
14 "Height": 600,
15 "Title": "View from 15th Floor",
16 "Thumbnail": {
17 "Url": "http://www.example.com/image/481989943",
18 "Height": 125,
19 "Width": "100"
21 "IDs": [116, 943, 234, 38793]
23 }]],
24 [[ [
26 "precision": "zip",
27 "Latitude": 37.7668,
28 "Longitude": -122.3959,
29 "Address": "",
30 "City": "SAN FRANCISCO",
31 "State": "CA",
32 "Zip": "94107",
33 "Country": "US"
36 "precision": "zip",
37 "Latitude": 37.371991,
38 "Longitude": -122.026020,
39 "Address": "",
40 "City": "SUNNYVALE",
41 "State": "CA",
42 "Zip": "94085",
43 "Country": "US"
45 ] ]],
46 [[[null,true,[1,2,3],"hello\"],[world!"] ]],
47 [[ [{"0":"tan\\\\","model\\\\":"sedan"},{"0":"red","model":"sports"}] ]],
48 [[ {"1":"one","2":"two","5":"five"} ]],
49 [=[ [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] ]=]
52 for i, v in ipairs(testStrings) do
53 print("Testing: #" .. i)
54 local dec = json.decode(v)
55 json.util.printValue(dec, "JSONVALUE")
56 local reenc = json.encode(dec)
57 print("RE_ENC: ", reenc)
58 local redec = json.decode(reenc)
59 json.util.printValue(redec, "REDECJSONVALUE")
60 end
62 local testValues = {
63 {[300] = {nil, true, 1,2,3, nil, 3}}
66 for _, v in ipairs(testValues) do
67 local ret = json.encode(v)
68 print(ret)
69 local dec = json.decode(ret)
70 json.util.printValue(dec, "Encoded value")
71 print("Re-encoded", json.encode(dec))
72 end