Artifact b6e655914d6bf281711323fb1fc7495cdcb9b029:
Wiki page
[
dkjson] by
dhkolf
2013-09-28 19:30:35.
0000: 44 20 32 30 31 33 2d 30 39 2d 32 38 54 31 39 3a D 2013-09-28T19:
0010: 33 30 3a 33 35 2e 31 37 30 0a 4c 20 64 6b 6a 73 30:35.170.L dkjs
0020: 6f 6e 0a 50 20 64 66 33 34 30 33 37 35 36 66 34 on.P df3403756f4
0030: 30 63 66 61 34 37 36 33 38 38 61 64 62 33 35 66 0cfa476388adb35f
0040: 30 62 39 36 62 61 33 33 34 64 61 39 31 0a 55 20 0b96ba334da91.U
0050: 64 68 6b 6f 6c 66 0a 57 20 37 38 33 35 0a 3c 68 dhkolf.W 7835.<h
0060: 31 3e 4a 53 4f 4e 20 4d 6f 64 75 6c 65 20 66 6f 1>JSON Module fo
0070: 72 20 4c 75 61 3c 2f 68 31 3e 0d 0a 0d 0a 3c 68 r Lua</h1>....<h
0080: 32 3e 49 6e 74 72 6f 64 75 63 74 69 6f 6e 3c 2f 2>Introduction</
0090: 68 32 3e 0d 0a 0d 0a 54 68 69 73 20 69 73 20 61 h2>....This is a
00a0: 20 4a 53 4f 4e 20 6d 6f 64 75 6c 65 20 77 72 69 JSON module wri
00b0: 74 74 65 6e 20 69 6e 20 5b 68 74 74 70 3a 2f 2f tten in [http://
00c0: 77 77 77 2e 6c 75 61 2e 6f 72 67 2f 7c 4c 75 61 www.lua.org/|Lua
00d0: 5d 2e 20 49 74 20 73 75 70 70 6f 72 74 73 20 55 ]. It supports U
00e0: 54 46 2d 38 2e 0d 0a 0d 0a 5b 68 74 74 70 3a 2f TF-8.....[http:/
00f0: 2f 77 77 77 2e 6a 73 6f 6e 2e 6f 72 67 2f 7c 4a /www.json.org/|J
0100: 53 4f 4e 20 28 4a 61 76 61 53 63 72 69 70 74 20 SON (JavaScript
0110: 4f 62 6a 65 63 74 20 4e 6f 74 61 74 69 6f 6e 29 Object Notation)
0120: 5d 20 69 73 20 61 20 66 6f 72 6d 61 74 20 66 6f ] is a format fo
0130: 72 20 73 65 72 69 61 6c 69 7a 69 6e 67 20 64 61 r serializing da
0140: 74 61 20 62 61 73 65 64 20 6f 6e 20 74 68 65 20 ta based on the
0150: 73 79 6e 74 61 78 20 66 6f 72 20 4a 61 76 61 53 syntax for JavaS
0160: 63 72 69 70 74 20 64 61 74 61 20 73 74 72 75 63 cript data struc
0170: 74 75 72 65 73 2e 20 20 49 74 20 69 73 20 61 6e tures. It is an
0180: 20 69 64 65 61 6c 20 66 6f 72 6d 61 74 20 66 6f ideal format fo
0190: 72 20 74 72 61 6e 73 6d 69 74 74 69 6e 67 20 64 r transmitting d
01a0: 61 74 61 20 62 65 74 77 65 65 6e 20 64 69 66 66 ata between diff
01b0: 65 72 65 6e 74 20 61 70 70 6c 69 63 61 74 69 6f erent applicatio
01c0: 6e 73 20 61 6e 64 20 63 6f 6d 6d 6f 6e 6c 79 20 ns and commonly
01d0: 75 73 65 64 20 66 6f 72 20 64 79 6e 61 6d 69 63 used for dynamic
01e0: 20 77 65 62 20 70 61 67 65 73 2e 20 20 49 74 20 web pages. It
01f0: 63 61 6e 20 61 6c 73 6f 20 62 65 20 75 73 65 64 can also be used
0200: 20 74 6f 20 73 61 76 65 20 4c 75 61 20 64 61 74 to save Lua dat
0210: 61 20 73 74 72 75 63 74 75 72 65 73 2c 20 62 75 a structures, bu
0220: 74 20 79 6f 75 20 73 68 6f 75 6c 64 20 62 65 20 t you should be
0230: 61 77 61 72 65 20 74 68 61 74 20 6e 6f 74 20 65 aware that not e
0240: 76 65 72 79 20 4c 75 61 20 74 61 62 6c 65 20 63 very Lua table c
0250: 61 6e 20 62 65 20 72 65 70 72 65 73 65 6e 74 65 an be represente
0260: 64 20 62 79 20 74 68 65 20 4a 53 4f 4e 20 73 74 d by the JSON st
0270: 61 6e 64 61 72 64 2e 20 20 46 6f 72 20 65 78 61 andard. For exa
0280: 6d 70 6c 65 20 74 61 62 6c 65 73 20 74 68 61 74 mple tables that
0290: 20 63 6f 6e 74 61 69 6e 20 62 6f 74 68 20 73 74 contain both st
02a0: 72 69 6e 67 20 6b 65 79 73 20 61 6e 64 20 61 6e ring keys and an
02b0: 20 61 72 72 61 79 20 70 61 72 74 20 63 61 6e 6e array part cann
02c0: 6f 74 20 62 65 20 65 78 61 63 74 6c 79 20 72 65 ot be exactly re
02d0: 70 72 65 73 65 6e 74 65 64 20 62 79 20 4a 53 4f presented by JSO
02e0: 4e 2e 20 20 59 6f 75 20 63 61 6e 20 73 6f 6c 76 N. You can solv
02f0: 65 20 74 68 69 73 20 62 79 20 70 75 74 74 69 6e e this by puttin
0300: 67 20 79 6f 75 72 20 61 72 72 61 79 20 64 61 74 g your array dat
0310: 61 20 69 6e 20 61 6e 20 65 78 70 6c 69 63 69 74 a in an explicit
0320: 20 73 75 62 74 61 62 6c 65 2e 0d 0a 0d 0a 64 6b subtable.....dk
0330: 6a 73 6f 6e 20 69 73 20 77 72 69 74 74 65 6e 20 json is written
0340: 69 6e 20 4c 75 61 20 77 69 74 68 6f 75 74 20 61 in Lua without a
0350: 6e 79 20 64 65 70 65 6e 64 65 6e 63 69 65 73 2c ny dependencies,
0360: 20 62 75 74 0d 0a 77 68 65 6e 20 5b 68 74 74 70 but..when [http
0370: 3a 2f 2f 77 77 77 2e 69 6e 66 2e 70 75 63 2d 72 ://www.inf.puc-r
0380: 69 6f 2e 62 72 2f 7e 72 6f 62 65 72 74 6f 2f 6c io.br/~roberto/l
0390: 70 65 67 2f 7c 4c 50 65 67 5d 20 69 73 20 61 76 peg/|LPeg] is av
03a0: 61 69 6c 61 62 6c 65 20 64 6b 6a 73 6f 6e 20 75 ailable dkjson u
03b0: 73 65 73 20 69 74 20 74 6f 20 73 70 65 65 64 20 ses it to speed
03c0: 75 70 20 64 65 63 6f 64 69 6e 67 2e 0d 0a 0d 0a up decoding.....
03d0: 3c 68 32 3e 44 6f 77 6e 6c 6f 61 64 3c 2f 68 32 <h2>Download</h2
03e0: 3e 0d 0a 20 20 2a 20 20 5b 2e 2f 72 61 77 2f 64 >.. * [./raw/d
03f0: 6b 6a 73 6f 6e 2e 6c 75 61 3f 6e 61 6d 65 3d 30 kjson.lua?name=0
0400: 62 37 32 35 65 39 65 39 39 31 31 37 62 37 31 61 b725e9e99117b71a
0410: 31 66 36 32 65 39 32 31 63 39 38 62 66 33 33 32 1f62e921c98bf332
0420: 37 61 63 38 38 30 39 20 7c 20 64 6b 6a 73 6f 6e 7ac8809 | dkjson
0430: 2e 6c 75 61 5d 0d 0a 0d 0a 54 68 65 20 66 75 6c .lua]....The ful
0440: 6c 20 5b 44 6f 63 75 6d 65 6e 74 61 74 69 6f 6e l [Documentation
0450: 7c 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 69 |documentation i
0460: 6e 63 6c 75 64 69 6e 67 20 74 68 65 20 6c 69 63 ncluding the lic
0470: 65 6e 73 65 5d 20 69 73 20 61 76 61 69 6c 61 62 ense] is availab
0480: 6c 65 20 68 65 72 65 20 69 6e 20 74 68 65 20 77 le here in the w
0490: 69 6b 69 20 6f 72 20 61 73 20 4d 61 72 6b 64 6f iki or as Markdo
04a0: 77 6e 20 74 65 78 74 20 69 6e 20 74 68 65 20 73 wn text in the s
04b0: 6f 75 72 63 65 20 66 69 6c 65 2e 0d 0a 0d 0a 64 ource file.....d
04c0: 6b 6a 73 6f 6e 20 69 73 20 66 72 65 65 20 73 6f kjson is free so
04d0: 66 74 77 61 72 65 20 72 65 6c 65 61 73 65 64 20 ftware released
04e0: 75 6e 64 65 72 20 74 68 65 20 73 61 6d 65 20 63 under the same c
04f0: 6f 6e 64 69 74 69 6f 6e 73 20 61 73 20 74 68 65 onditions as the
0500: 20 4c 75 61 20 69 6e 74 65 72 70 72 65 74 65 72 Lua interpreter
0510: 2e 20 20 50 6c 65 61 73 65 20 72 65 6d 65 6d 62 . Please rememb
0520: 65 72 20 74 6f 20 6d 65 6e 74 69 6f 6e 20 65 78 er to mention ex
0530: 74 65 72 6e 61 6c 20 63 6f 64 65 20 79 6f 75 20 ternal code you
0540: 61 72 65 20 75 73 69 6e 67 20 69 6e 20 79 6f 75 are using in you
0550: 72 20 73 6f 66 74 77 61 72 65 2e 0d 0a 0d 0a 3c r software.....<
0560: 68 32 3e 45 78 61 6d 70 6c 65 73 3c 2f 68 32 3e h2>Examples</h2>
0570: 0d 0a 0d 0a 3c 68 33 3e 45 6e 63 6f 64 69 6e 67 ....<h3>Encoding
0580: 3c 2f 68 33 3e 0d 0a 0d 0a 3c 70 72 65 3e 3c 63 </h3>....<pre><c
0590: 6f 64 65 3e 3c 6e 6f 77 69 6b 69 3e 0d 0a 3c 73 ode><nowiki>..<s
05a0: 70 61 6e 20 63 6c 61 73 73 3d 22 6c 75 61 6b 65 pan class="luake
05b0: 79 77 6f 72 64 22 3e 6c 6f 63 61 6c 3c 2f 73 70 yword">local</sp
05c0: 61 6e 3e 20 6a 73 6f 6e 20 3d 20 3c 73 70 61 6e an> json = <span
05d0: 20 63 6c 61 73 73 3d 22 6c 75 61 6c 69 62 72 61 class="lualibra
05e0: 72 79 22 3e 72 65 71 75 69 72 65 3c 2f 73 70 61 ry">require</spa
05f0: 6e 3e 20 28 3c 73 70 61 6e 20 63 6c 61 73 73 3d n> (<span class=
0600: 22 6c 75 61 73 74 72 69 6e 67 22 3e 22 64 6b 6a "luastring">"dkj
0610: 73 6f 6e 22 3c 2f 73 70 61 6e 3e 29 0d 0a 0d 0a son"</span>)....
0620: 3c 73 70 61 6e 20 63 6c 61 73 73 3d 22 6c 75 61 <span class="lua
0630: 6b 65 79 77 6f 72 64 22 3e 6c 6f 63 61 6c 3c 2f keyword">local</
0640: 73 70 61 6e 3e 20 74 62 6c 20 3d 20 7b 0d 0a 20 span> tbl = {..
0650: 20 61 6e 69 6d 61 6c 73 20 3d 20 7b 20 3c 73 70 animals = { <sp
0660: 61 6e 20 63 6c 61 73 73 3d 22 6c 75 61 73 74 72 an class="luastr
0670: 69 6e 67 22 3e 22 64 6f 67 22 3c 2f 73 70 61 6e ing">"dog"</span
0680: 3e 2c 20 3c 73 70 61 6e 20 63 6c 61 73 73 3d 22 >, <span class="
0690: 6c 75 61 73 74 72 69 6e 67 22 3e 22 63 61 74 22 luastring">"cat"
06a0: 3c 2f 73 70 61 6e 3e 2c 20 3c 73 70 61 6e 20 63 </span>, <span c
06b0: 6c 61 73 73 3d 22 6c 75 61 73 74 72 69 6e 67 22 lass="luastring"
06c0: 3e 22 61 61 72 64 76 61 72 6b 22 3c 2f 73 70 61 >"aardvark"</spa
06d0: 6e 3e 20 7d 2c 0d 0a 20 20 69 6e 73 74 72 75 6d n> },.. instrum
06e0: 65 6e 74 73 20 3d 20 7b 20 3c 73 70 61 6e 20 63 ents = { <span c
06f0: 6c 61 73 73 3d 22 6c 75 61 73 74 72 69 6e 67 22 lass="luastring"
0700: 3e 22 76 69 6f 6c 69 6e 22 3c 2f 73 70 61 6e 3e >"violin"</span>
0710: 2c 20 3c 73 70 61 6e 20 63 6c 61 73 73 3d 22 6c , <span class="l
0720: 75 61 73 74 72 69 6e 67 22 3e 22 74 72 6f 6d 62 uastring">"tromb
0730: 6f 6e 65 22 3c 2f 73 70 61 6e 3e 2c 20 3c 73 70 one"</span>, <sp
0740: 61 6e 20 63 6c 61 73 73 3d 22 6c 75 61 73 74 72 an class="luastr
0750: 69 6e 67 22 3e 22 74 68 65 72 65 6d 69 6e 22 3c ing">"theremin"<
0760: 2f 73 70 61 6e 3e 20 7d 2c 0d 0a 20 20 62 75 67 /span> },.. bug
0770: 73 20 3d 20 6a 73 6f 6e 2e 6e 75 6c 6c 2c 0d 0a s = json.null,..
0780: 20 20 74 72 65 65 73 20 3d 20 3c 73 70 61 6e 20 trees = <span
0790: 63 6c 61 73 73 3d 22 6c 75 61 6b 65 79 77 6f 72 class="luakeywor
07a0: 64 22 3e 6e 69 6c 3c 2f 73 70 61 6e 3e 0d 0a 7d d">nil</span>..}
07b0: 0d 0a 0d 0a 3c 73 70 61 6e 20 63 6c 61 73 73 3d ....<span class=
07c0: 22 6c 75 61 6b 65 79 77 6f 72 64 22 3e 6c 6f 63 "luakeyword">loc
07d0: 61 6c 3c 2f 73 70 61 6e 3e 20 73 74 72 20 3d 20 al</span> str =
07e0: 6a 73 6f 6e 2e 65 6e 63 6f 64 65 20 28 74 62 6c json.encode (tbl
07f0: 2c 20 7b 20 69 6e 64 65 6e 74 20 3d 20 3c 73 70 , { indent = <sp
0800: 61 6e 20 63 6c 61 73 73 3d 22 6c 75 61 6b 65 79 an class="luakey
0810: 77 6f 72 64 22 3e 74 72 75 65 3c 2f 73 70 61 6e word">true</span
0820: 3e 20 7d 29 0d 0a 0d 0a 3c 73 70 61 6e 20 63 6c > })....<span cl
0830: 61 73 73 3d 22 6c 75 61 6c 69 62 72 61 72 79 22 ass="lualibrary"
0840: 3e 70 72 69 6e 74 3c 2f 73 70 61 6e 3e 20 28 73 >print</span> (s
0850: 74 72 29 0d 0a 3c 2f 6e 6f 77 69 6b 69 3e 3c 2f tr)..</nowiki></
0860: 63 6f 64 65 3e 3c 2f 70 72 65 3e 0d 0a 0d 0a 3c code></pre>....<
0870: 68 34 3e 4f 75 74 70 75 74 3c 2f 68 34 3e 0d 0a h4>Output</h4>..
0880: 0d 0a 3c 70 72 65 3e 3c 63 6f 64 65 3e 3c 6e 6f ..<pre><code><no
0890: 77 69 6b 69 3e 0d 0a 7b 0d 0a 20 20 22 62 75 67 wiki>..{.. "bug
08a0: 73 22 3a 6e 75 6c 6c 2c 0d 0a 20 20 22 69 6e 73 s":null,.. "ins
08b0: 74 72 75 6d 65 6e 74 73 22 3a 5b 22 76 69 6f 6c truments":["viol
08c0: 69 6e 22 2c 22 74 72 6f 6d 62 6f 6e 65 22 2c 22 in","trombone","
08d0: 74 68 65 72 65 6d 69 6e 22 5d 2c 0d 0a 20 20 22 theremin"],.. "
08e0: 61 6e 69 6d 61 6c 73 22 3a 5b 22 64 6f 67 22 2c animals":["dog",
08f0: 22 63 61 74 22 2c 22 61 61 72 64 76 61 72 6b 22 "cat","aardvark"
0900: 5d 0d 0a 7d 0d 0a 3c 2f 6e 6f 77 69 6b 69 3e 3c ]..}..</nowiki><
0910: 2f 63 6f 64 65 3e 3c 2f 70 72 65 3e 0d 0a 0d 0a /code></pre>....
0920: 3c 68 33 3e 44 65 63 6f 64 69 6e 67 3c 2f 68 33 <h3>Decoding</h3
0930: 3e 0d 0a 0d 0a 3c 70 72 65 3e 3c 63 6f 64 65 3e >....<pre><code>
0940: 3c 6e 6f 77 69 6b 69 3e 0d 0a 3c 73 70 61 6e 20 <nowiki>..<span
0950: 63 6c 61 73 73 3d 22 6c 75 61 6b 65 79 77 6f 72 class="luakeywor
0960: 64 22 3e 6c 6f 63 61 6c 3c 2f 73 70 61 6e 3e 20 d">local</span>
0970: 6a 73 6f 6e 20 3d 20 3c 73 70 61 6e 20 63 6c 61 json = <span cla
0980: 73 73 3d 22 6c 75 61 6c 69 62 72 61 72 79 22 3e ss="lualibrary">
0990: 72 65 71 75 69 72 65 3c 2f 73 70 61 6e 3e 20 28 require</span> (
09a0: 3c 73 70 61 6e 20 63 6c 61 73 73 3d 22 6c 75 61 <span class="lua
09b0: 73 74 72 69 6e 67 22 3e 22 64 6b 6a 73 6f 6e 22 string">"dkjson"
09c0: 3c 2f 73 70 61 6e 3e 29 0d 0a 0d 0a 3c 73 70 61 </span>)....<spa
09d0: 6e 20 63 6c 61 73 73 3d 22 6c 75 61 6b 65 79 77 n class="luakeyw
09e0: 6f 72 64 22 3e 6c 6f 63 61 6c 3c 2f 73 70 61 6e ord">local</span
09f0: 3e 20 73 74 72 20 3d 20 3c 73 70 61 6e 20 63 6c > str = <span cl
0a00: 61 73 73 3d 22 6c 75 61 73 74 72 69 6e 67 22 3e ass="luastring">
0a10: 5b 5b 0d 0a 7b 0d 0a 20 20 22 6e 75 6d 62 65 72 [[..{.. "number
0a20: 73 22 3a 20 5b 20 32 2c 20 33 2c 20 2d 32 30 2e s": [ 2, 3, -20.
0a30: 32 33 65 2b 32 2c 20 2d 34 20 5d 2c 0d 0a 20 20 23e+2, -4 ],..
0a40: 22 63 75 72 72 65 6e 63 79 22 3a 20 22 5c 75 32 "currency": "\u2
0a50: 30 41 43 22 0d 0a 7d 0d 0a 5d 5d 3c 2f 73 70 61 0AC"..}..]]</spa
0a60: 6e 3e 0d 0a 0d 0a 3c 73 70 61 6e 20 63 6c 61 73 n>....<span clas
0a70: 73 3d 22 6c 75 61 6b 65 79 77 6f 72 64 22 3e 6c s="luakeyword">l
0a80: 6f 63 61 6c 3c 2f 73 70 61 6e 3e 20 6f 62 6a 2c ocal</span> obj,
0a90: 20 70 6f 73 2c 20 65 72 72 20 3d 20 6a 73 6f 6e pos, err = json
0aa0: 2e 64 65 63 6f 64 65 20 28 73 74 72 2c 20 31 2c .decode (str, 1,
0ab0: 20 3c 73 70 61 6e 20 63 6c 61 73 73 3d 22 6c 75 <span class="lu
0ac0: 61 6b 65 79 77 6f 72 64 22 3e 6e 69 6c 3c 2f 73 akeyword">nil</s
0ad0: 70 61 6e 3e 29 0d 0a 3c 73 70 61 6e 20 63 6c 61 pan>)..<span cla
0ae0: 73 73 3d 22 6c 75 61 6b 65 79 77 6f 72 64 22 3e ss="luakeyword">
0af0: 69 66 3c 2f 73 70 61 6e 3e 20 65 72 72 20 3c 73 if</span> err <s
0b00: 70 61 6e 20 63 6c 61 73 73 3d 22 6c 75 61 6b 65 pan class="luake
0b10: 79 77 6f 72 64 22 3e 74 68 65 6e 3c 2f 73 70 61 yword">then</spa
0b20: 6e 3e 0d 0a 20 20 3c 73 70 61 6e 20 63 6c 61 73 n>.. <span clas
0b30: 73 3d 22 6c 75 61 6c 69 62 72 61 72 79 22 3e 70 s="lualibrary">p
0b40: 72 69 6e 74 3c 2f 73 70 61 6e 3e 20 28 3c 73 70 rint</span> (<sp
0b50: 61 6e 20 63 6c 61 73 73 3d 22 6c 75 61 73 74 72 an class="luastr
0b60: 69 6e 67 22 3e 22 45 72 72 6f 72 3a 22 3c 2f 73 ing">"Error:"</s
0b70: 70 61 6e 3e 2c 20 65 72 72 29 0d 0a 3c 73 70 61 pan>, err)..<spa
0b80: 6e 20 63 6c 61 73 73 3d 22 6c 75 61 6b 65 79 77 n class="luakeyw
0b90: 6f 72 64 22 3e 65 6c 73 65 3c 2f 73 70 61 6e 3e ord">else</span>
0ba0: 0d 0a 20 20 3c 73 70 61 6e 20 63 6c 61 73 73 3d .. <span class=
0bb0: 22 6c 75 61 6c 69 62 72 61 72 79 22 3e 70 72 69 "lualibrary">pri
0bc0: 6e 74 3c 2f 73 70 61 6e 3e 20 28 3c 73 70 61 6e nt</span> (<span
0bd0: 20 63 6c 61 73 73 3d 22 6c 75 61 73 74 72 69 6e class="luastrin
0be0: 67 22 3e 22 63 75 72 72 65 6e 63 79 22 3c 2f 73 g">"currency"</s
0bf0: 70 61 6e 3e 2c 20 6f 62 6a 2e 63 75 72 72 65 6e pan>, obj.curren
0c00: 63 79 29 0d 0a 20 20 3c 73 70 61 6e 20 63 6c 61 cy).. <span cla
0c10: 73 73 3d 22 6c 75 61 6b 65 79 77 6f 72 64 22 3e ss="luakeyword">
0c20: 66 6f 72 3c 2f 73 70 61 6e 3e 20 69 20 3d 20 31 for</span> i = 1
0c30: 2c 23 6f 62 6a 2e 6e 75 6d 62 65 72 73 20 3c 73 ,#obj.numbers <s
0c40: 70 61 6e 20 63 6c 61 73 73 3d 22 6c 75 61 6b 65 pan class="luake
0c50: 79 77 6f 72 64 22 3e 64 6f 3c 2f 73 70 61 6e 3e yword">do</span>
0c60: 0d 0a 20 20 20 20 3c 73 70 61 6e 20 63 6c 61 73 .. <span clas
0c70: 73 3d 22 6c 75 61 6c 69 62 72 61 72 79 22 3e 70 s="lualibrary">p
0c80: 72 69 6e 74 3c 2f 73 70 61 6e 3e 20 28 69 2c 20 rint</span> (i,
0c90: 6f 62 6a 2e 6e 75 6d 62 65 72 73 5b 69 5d 29 0d obj.numbers[i]).
0ca0: 0a 20 20 3c 73 70 61 6e 20 63 6c 61 73 73 3d 22 . <span class="
0cb0: 6c 75 61 6b 65 79 77 6f 72 64 22 3e 65 6e 64 3c luakeyword">end<
0cc0: 2f 73 70 61 6e 3e 0d 0a 3c 73 70 61 6e 20 63 6c /span>..<span cl
0cd0: 61 73 73 3d 22 6c 75 61 6b 65 79 77 6f 72 64 22 ass="luakeyword"
0ce0: 3e 65 6e 64 3c 2f 73 70 61 6e 3e 0d 0a 0d 0a 3c >end</span>....<
0cf0: 2f 6e 6f 77 69 6b 69 3e 3c 2f 63 6f 64 65 3e 3c /nowiki></code><
0d00: 2f 70 72 65 3e 0d 0a 0d 0a 0d 0a 3c 68 34 3e 4f /pre>......<h4>O
0d10: 75 74 70 75 74 3c 2f 68 34 3e 0d 0a 0d 0a 3c 70 utput</h4>....<p
0d20: 72 65 3e 3c 6e 6f 77 69 6b 69 3e 0d 0a 63 75 72 re><nowiki>..cur
0d30: 72 65 6e 63 79 09 e2 82 ac 0d 0a 31 09 32 0d 0a rency......1.2..
0d40: 32 09 33 0d 0a 33 09 2d 32 30 32 33 0d 0a 34 09 2.3..3.-2023..4.
0d50: 2d 34 0d 0a 3c 2f 6e 6f 77 69 6b 69 3e 3c 2f 70 -4..</nowiki></p
0d60: 72 65 3e 0d 0a 0d 0a 3c 68 32 3e 56 65 72 73 69 re>....<h2>Versi
0d70: 6f 6e 73 3c 2f 68 32 3e 0d 0a 0d 0a 3c 68 33 3e ons</h2>....<h3>
0d80: 56 65 72 73 69 6f 6e 20 32 2e 34 20 28 32 30 31 Version 2.4 (201
0d90: 33 2d 30 39 2d 32 38 29 3c 2f 68 33 3e 0d 0a 0d 3-09-28)</h3>...
0da0: 0a 20 20 2a 20 20 44 6f 77 6e 6c 6f 61 64 20 5b . * Download [
0db0: 2e 2f 72 61 77 2f 64 6b 6a 73 6f 6e 2e 6c 75 61 ./raw/dkjson.lua
0dc0: 3f 6e 61 6d 65 3d 30 62 37 32 35 65 39 65 39 39 ?name=0b725e9e99
0dd0: 31 31 37 62 37 31 61 31 66 36 32 65 39 32 31 63 117b71a1f62e921c
0de0: 39 38 62 66 33 33 32 37 61 63 38 38 30 39 20 7c 98bf3327ac8809 |
0df0: 20 64 6b 6a 73 6f 6e 2e 6c 75 61 20 76 65 72 73 dkjson.lua vers
0e00: 69 6f 6e 20 32 2e 34 5d 0d 0a 0d 0a 43 68 61 6e ion 2.4]....Chan
0e10: 67 65 73 20 73 69 6e 63 65 20 76 65 72 73 69 6f ges since versio
0e20: 6e 20 32 2e 33 3a 0d 0a 0d 0a 20 20 2a 20 20 46 n 2.3:.... * F
0e30: 69 78 65 64 20 65 6e 63 6f 64 69 6e 67 20 61 6e ixed encoding an
0e40: 64 20 64 65 63 6f 64 69 6e 67 20 6f 66 20 6e 75 d decoding of nu
0e50: 6d 62 65 72 73 20 69 6e 20 64 69 66 66 65 72 65 mbers in differe
0e60: 6e 74 20 6e 75 6d 65 72 69 63 20 6c 6f 63 61 6c nt numeric local
0e70: 65 73 2e 0d 0a 20 20 2a 20 20 50 72 65 76 65 6e es... * Preven
0e80: 74 20 75 73 69 6e 67 20 76 65 72 73 69 6f 6e 20 t using version
0e90: 30 2e 31 31 20 6f 66 20 4c 50 65 67 20 28 63 61 0.11 of LPeg (ca
0ea0: 75 73 65 73 20 73 65 67 6d 65 6e 74 61 74 69 6f uses segmentatio
0eb0: 6e 20 66 61 75 6c 74 73 20 6f 6e 0d 0a 20 20 20 n faults on..
0ec0: 20 20 73 6f 6d 65 20 73 79 73 74 65 6d 73 29 2e some systems).
0ed0: 0d 0a 0d 0a 3c 68 33 3e 56 65 72 73 69 6f 6e 20 ....<h3>Version
0ee0: 31 2e 33 20 28 32 30 31 33 2d 30 39 2d 32 38 29 1.3 (2013-09-28)
0ef0: 3c 2f 68 33 3e 0d 0a 0d 0a 20 20 2a 20 20 44 6f </h3>.... * Do
0f00: 77 6e 6c 6f 61 64 20 5b 2e 2f 72 61 77 2f 64 6b wnload [./raw/dk
0f10: 6a 73 6f 6e 2e 6c 75 61 3f 6e 61 6d 65 3d 31 34 json.lua?name=14
0f20: 32 66 65 31 36 64 31 34 61 37 31 61 34 37 37 65 2fe16d14a71a477e
0f30: 65 65 39 38 32 32 31 33 33 65 32 64 36 31 65 61 ee9822133e2d61ea
0f40: 66 33 35 34 34 33 20 7c 20 64 6b 6a 73 6f 6e 2e f35443 | dkjson.
0f50: 6c 75 61 20 76 65 72 73 69 6f 6e 20 31 2e 33 5d lua version 1.3]
0f60: 0d 0a 0d 0a 43 68 61 6e 67 65 73 20 73 69 6e 63 ....Changes sinc
0f70: 65 20 76 65 72 73 69 6f 6e 20 31 2e 32 3a 0d 0a e version 1.2:..
0f80: 0d 0a 20 20 2a 20 20 46 69 78 65 64 20 65 6e 63 .. * Fixed enc
0f90: 6f 64 69 6e 67 20 61 6e 64 20 64 65 63 6f 64 69 oding and decodi
0fa0: 6e 67 20 6f 66 20 6e 75 6d 62 65 72 73 20 69 6e ng of numbers in
0fb0: 20 64 69 66 66 65 72 65 6e 74 20 6e 75 6d 65 72 different numer
0fc0: 69 63 20 6c 6f 63 61 6c 65 73 2e 0d 0a 0d 0a 3c ic locales.....<
0fd0: 68 33 3e 56 65 72 73 69 6f 6e 20 32 2e 33 20 28 h3>Version 2.3 (
0fe0: 32 30 31 33 2d 30 34 2d 31 34 29 3c 2f 68 33 3e 2013-04-14)</h3>
0ff0: 0d 0a 0d 0a 20 20 2a 20 20 44 6f 77 6e 6c 6f 61 .... * Downloa
1000: 64 20 5b 2e 2f 72 61 77 2f 64 6b 6a 73 6f 6e 2e d [./raw/dkjson.
1010: 6c 75 61 3f 6e 61 6d 65 3d 31 61 37 39 36 39 61 lua?name=1a7969a
1020: 65 33 66 66 39 61 36 65 30 32 36 38 65 36 35 35 e3ff9a6e0268e655
1030: 35 64 33 31 30 39 32 32 31 33 30 36 30 66 64 36 5d31092213060fd6
1040: 32 20 7c 20 64 6b 6a 73 6f 6e 2e 6c 75 61 20 76 2 | dkjson.lua v
1050: 65 72 73 69 6f 6e 20 32 2e 33 5d 0d 0a 0d 0a 43 ersion 2.3]....C
1060: 68 61 6e 67 65 73 20 73 69 6e 63 65 20 76 65 72 hanges since ver
1070: 73 69 6f 6e 20 32 2e 32 3a 0d 0a 0d 0a 20 20 2a sion 2.2:.... *
1080: 20 20 43 6f 72 72 65 63 74 65 64 20 74 68 65 20 Corrected the
1090: 72 61 6e 67 65 20 6f 66 20 65 73 63 61 70 65 64 range of escaped
10a0: 20 63 68 61 72 61 63 74 65 72 73 2e 20 20 41 6d characters. Am
10b0: 6f 6e 67 20 6f 74 68 65 72 20 63 68 61 72 61 63 ong other charac
10c0: 74 65 72 73 0d 0a 20 20 20 20 20 55 2b 32 30 32 ters.. U+202
10d0: 39 20 77 61 73 20 6d 69 73 73 69 6e 67 2c 20 77 9 was missing, w
10e0: 68 69 63 68 20 77 6f 75 6c 64 20 63 61 75 73 65 hich would cause
10f0: 20 74 72 6f 75 62 6c 65 20 77 68 65 6e 20 5b 68 trouble when [h
1100: 74 74 70 3a 2f 2f 74 69 6d 65 6c 65 73 73 72 65 ttp://timelessre
1110: 70 6f 2e 63 6f 6d 2f 6a 73 6f 6e 2d 69 73 6e 74 po.com/json-isnt
1120: 2d 61 2d 6a 61 76 61 73 63 72 69 70 74 2d 73 75 -a-javascript-su
1130: 62 73 65 74 7c 70 61 72 73 65 64 20 62 79 20 61 bset|parsed by a
1140: 0d 0a 20 20 20 20 20 4a 61 76 61 53 63 72 69 70 .. JavaScrip
1150: 74 20 69 6e 74 65 72 70 72 65 74 65 72 2e 5d 0d t interpreter.].
1160: 0a 20 20 2a 20 20 41 64 64 65 64 20 6f 70 74 69 . * Added opti
1170: 6f 6e 73 20 74 6f 20 72 65 67 69 73 74 65 72 20 ons to register
1180: 74 68 65 20 6d 6f 64 75 6c 65 20 74 61 62 6c 65 the module table
1190: 20 69 6e 20 61 20 67 6c 6f 62 61 6c 20 76 61 72 in a global var
11a0: 69 61 62 6c 65 2e 0d 0a 20 20 20 20 20 54 68 69 iable... Thi
11b0: 73 20 69 73 20 75 73 65 66 75 6c 20 69 6e 20 65 s is useful in e
11c0: 6e 76 69 72 6f 6e 6d 65 6e 74 73 20 77 68 65 72 nvironments wher
11d0: 65 20 66 75 6e 63 74 69 6f 6e 73 20 73 69 6d 69 e functions simi
11e0: 6c 61 72 20 74 6f 20 72 65 71 75 69 72 65 20 61 lar to require a
11f0: 72 65 0d 0a 20 20 20 20 20 6e 6f 74 20 61 76 61 re.. not ava
1200: 69 6c 61 62 6c 65 2e 0d 0a 0d 0a 3c 68 33 3e 56 ilable.....<h3>V
1210: 65 72 73 69 6f 6e 20 31 2e 32 20 28 32 30 31 33 ersion 1.2 (2013
1220: 2d 30 34 2d 31 34 29 3c 2f 68 33 3e 0d 0a 0d 0a -04-14)</h3>....
1230: 20 20 2a 20 20 44 6f 77 6e 6c 6f 61 64 20 5b 2e * Download [.
1240: 2f 72 61 77 2f 64 6b 6a 73 6f 6e 2e 6c 75 61 3f /raw/dkjson.lua?
1250: 6e 61 6d 65 3d 34 61 30 35 61 64 38 31 64 31 30 name=4a05ad81d10
1260: 65 38 63 64 35 63 32 37 66 37 65 62 39 38 35 37 e8cd5c27f7eb9857
1270: 31 37 66 65 66 62 32 36 66 38 30 34 34 20 7c 20 17fefb26f8044 |
1280: 64 6b 6a 73 6f 6e 2e 6c 75 61 20 76 65 72 73 69 dkjson.lua versi
1290: 6f 6e 20 31 2e 32 5d 0d 0a 0d 0a 43 68 61 6e 67 on 1.2]....Chang
12a0: 65 73 20 73 69 6e 63 65 20 76 65 72 73 69 6f 6e es since version
12b0: 20 31 2e 31 3a 0d 0a 0d 0a 20 20 2a 20 20 43 6f 1.1:.... * Co
12c0: 72 72 65 63 74 65 64 20 74 68 65 20 72 61 6e 67 rrected the rang
12d0: 65 20 6f 66 20 65 73 63 61 70 65 64 20 63 68 61 e of escaped cha
12e0: 72 61 63 74 65 72 73 2e 20 20 41 6d 6f 6e 67 20 racters. Among
12f0: 6f 74 68 65 72 20 63 68 61 72 61 63 74 65 72 73 other characters
1300: 0d 0a 20 20 20 20 20 55 2b 32 30 32 39 20 77 61 .. U+2029 wa
1310: 73 20 6d 69 73 73 69 6e 67 2c 20 77 68 69 63 68 s missing, which
1320: 20 77 6f 75 6c 64 20 63 61 75 73 65 20 74 72 6f would cause tro
1330: 75 62 6c 65 20 77 68 65 6e 20 70 61 72 73 65 64 uble when parsed
1340: 20 62 79 20 61 0d 0a 20 20 20 20 20 4a 61 76 61 by a.. Java
1350: 53 63 72 69 70 74 20 69 6e 74 65 72 70 72 65 74 Script interpret
1360: 65 72 2e 0d 0a 20 20 2a 20 20 4c 6f 63 61 74 69 er... * Locati
1370: 6f 6e 73 20 66 6f 72 20 65 72 72 6f 72 20 6d 65 ons for error me
1380: 73 73 61 67 65 73 20 77 65 72 65 20 6f 66 66 20 ssages were off
1390: 62 79 20 6f 6e 65 20 69 6e 20 74 68 65 20 66 69 by one in the fi
13a0: 72 73 74 20 6c 69 6e 65 2e 0d 0a 0d 0a 0d 0a 3c rst line.......<
13b0: 68 33 3e 56 65 72 73 69 6f 6e 20 32 2e 32 20 28 h3>Version 2.2 (
13c0: 32 30 31 32 2d 30 34 2d 32 38 29 3c 2f 68 33 3e 2012-04-28)</h3>
13d0: 0d 0a 0d 0a 20 20 2a 20 20 44 6f 77 6e 6c 6f 61 .... * Downloa
13e0: 64 20 5b 2e 2f 72 61 77 2f 64 6b 6a 73 6f 6e 2e d [./raw/dkjson.
13f0: 6c 75 61 3f 6e 61 6d 65 3d 32 65 30 38 33 32 62 lua?name=2e0832b
1400: 34 30 32 37 36 31 34 64 35 64 35 63 37 30 38 61 4027614d5d5c708a
1410: 39 37 31 64 34 66 31 63 36 65 63 30 34 61 66 66 971d4f1c6ec04aff
1420: 62 20 7c 20 64 6b 6a 73 6f 6e 2e 6c 75 61 20 76 b | dkjson.lua v
1430: 65 72 73 69 6f 6e 20 32 2e 32 5d 0d 0a 0d 0a 43 ersion 2.2]....C
1440: 68 61 6e 67 65 73 20 73 69 6e 63 65 20 76 65 72 hanges since ver
1450: 73 69 6f 6e 20 32 2e 31 3a 0d 0a 0d 0a 20 20 2a sion 2.1:.... *
1460: 20 20 5f 5f 6a 73 6f 6e 74 79 70 65 20 69 73 20 __jsontype is
1470: 6f 6e 6c 79 20 75 73 65 64 20 66 6f 72 20 65 6d only used for em
1480: 70 74 79 20 74 61 62 6c 65 73 2e 0d 0a 20 20 2a pty tables... *
1490: 20 20 49 74 20 69 73 20 70 6f 73 73 69 62 6c 65 It is possible
14a0: 20 74 6f 20 64 65 63 6f 64 65 20 74 61 62 6c 65 to decode table
14b0: 73 20 77 69 74 68 6f 75 74 20 61 73 73 69 67 6e s without assign
14c0: 69 6e 67 20 6d 65 74 61 74 61 62 6c 65 73 2e 0d ing metatables..
14d0: 0a 20 20 2a 20 20 4c 6f 63 61 74 69 6f 6e 73 20 . * Locations
14e0: 66 6f 72 20 65 72 72 6f 72 20 6d 65 73 73 61 67 for error messag
14f0: 65 73 20 77 65 72 65 20 6f 66 66 20 62 79 20 6f es were off by o
1500: 6e 65 20 69 6e 20 74 68 65 20 66 69 72 73 74 20 ne in the first
1510: 6c 69 6e 65 2e 0d 0a 20 20 2a 20 20 54 68 65 72 line... * Ther
1520: 65 20 69 73 20 6e 6f 20 4c 50 65 67 20 76 65 72 e is no LPeg ver
1530: 73 69 6f 6e 20 6f 66 20 6a 73 6f 6e 2e 71 75 6f sion of json.quo
1540: 74 65 73 74 72 69 6e 67 20 61 6e 79 6d 6f 72 65 testring anymore
1550: 2e 0d 0a 0d 0a 3c 68 33 3e 56 65 72 73 69 6f 6e .....<h3>Version
1560: 20 32 2e 31 20 28 32 30 31 31 2d 30 37 2d 30 38 2.1 (2011-07-08
1570: 29 3c 2f 68 33 3e 0d 0a 0d 0a 20 20 2a 20 20 44 )</h3>.... * D
1580: 6f 77 6e 6c 6f 61 64 20 5b 2e 2f 72 61 77 2f 64 ownload [./raw/d
1590: 6b 6a 73 6f 6e 2e 6c 75 61 3f 6e 61 6d 65 3d 36 kjson.lua?name=6
15a0: 62 62 36 62 39 62 36 61 35 37 63 30 30 31 33 63 bb6b9b6a57c0013c
15b0: 61 61 66 37 34 61 30 62 65 32 31 32 63 32 30 63 aaf74a0be212c20c
15c0: 65 36 63 66 36 38 39 20 7c 20 64 6b 6a 73 6f 6e e6cf689 | dkjson
15d0: 2e 6c 75 61 20 76 65 72 73 69 6f 6e 20 32 2e 31 .lua version 2.1
15e0: 5d 0d 0a 0d 0a 43 68 61 6e 67 65 73 20 73 69 6e ]....Changes sin
15f0: 63 65 20 76 65 72 73 69 6f 6e 20 32 2e 30 3a 0d ce version 2.0:.
1600: 0a 0d 0a 20 20 2a 20 20 43 68 61 6e 67 65 64 20 ... * Changed
1610: 74 68 65 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f the documentatio
1620: 6e 20 74 6f 20 4d 61 72 6b 64 6f 77 6e 20 66 6f n to Markdown fo
1630: 72 6d 61 74 2e 0d 0a 20 20 2a 20 20 4c 50 65 67 rmat... * LPeg
1640: 20 69 73 20 6e 6f 77 20 70 61 72 73 69 6e 67 20 is now parsing
1650: 6f 6e 6c 79 20 61 20 73 69 6e 67 6c 65 20 76 61 only a single va
1660: 6c 75 65 20 61 74 20 61 20 74 69 6d 65 20 74 6f lue at a time to
1670: 20 61 76 6f 69 64 20 72 75 6e 6e 69 6e 67 0d 0a avoid running..
1680: 20 20 20 20 20 6f 75 74 20 6f 66 20 4c 75 61 20 out of Lua
1690: 73 74 61 63 6b 20 66 6f 72 20 62 69 67 20 61 72 stack for big ar
16a0: 72 61 79 73 20 61 6e 64 20 6f 62 6a 65 63 74 73 rays and objects
16b0: 2e 0d 0a 20 20 2a 20 20 52 65 61 64 20 5f 5f 74 ... * Read __t
16c0: 6f 6a 73 6f 6e 2c 20 5f 5f 6a 73 6f 6e 74 79 70 ojson, __jsontyp
16d0: 65 20 61 6e 64 20 5f 5f 6a 73 6f 6e 6f 72 64 65 e and __jsonorde
16e0: 72 20 65 76 65 6e 20 66 72 6f 6d 20 62 6c 6f 63 r even from bloc
16f0: 6b 65 64 20 6d 65 74 61 74 61 62 6c 65 73 0d 0a ked metatables..
1700: 20 20 20 20 20 74 68 72 6f 75 67 68 20 74 68 65 through the
1710: 20 64 65 62 75 67 20 6d 6f 64 75 6c 65 2e 0d 0a debug module...
1720: 20 20 2a 20 20 46 69 78 65 64 20 64 65 63 6f 64 * Fixed decod
1730: 69 6e 67 20 73 69 6e 67 6c 65 20 6e 75 6d 62 65 ing single numbe
1740: 72 73 20 28 6f 6e 6c 79 20 61 66 66 65 63 74 65 rs (only affecte
1750: 64 20 74 68 65 20 6e 6f 6e 2d 4c 50 65 67 20 6d d the non-LPeg m
1760: 6f 64 65 29 2e 0d 0a 20 20 2a 20 20 43 6f 72 72 ode)... * Corr
1770: 65 63 74 65 64 20 74 68 65 20 72 61 6e 67 65 20 ected the range
1780: 6f 66 20 65 73 63 61 70 65 64 20 55 6e 69 63 6f of escaped Unico
1790: 64 65 20 63 6f 6e 74 72 6f 6c 20 63 68 61 72 61 de control chara
17a0: 63 74 65 72 73 2e 0d 0a 0d 0a 3c 68 33 3e 56 65 cters.....<h3>Ve
17b0: 72 73 69 6f 6e 20 31 2e 31 20 28 32 30 31 31 2d rsion 1.1 (2011-
17c0: 30 37 2d 30 38 29 3c 2f 68 33 3e 0d 0a 0d 0a 20 07-08)</h3>....
17d0: 20 2a 20 20 44 6f 77 6e 6c 6f 61 64 20 5b 2e 2f * Download [./
17e0: 72 61 77 2f 64 6b 6a 73 6f 6e 2e 6c 75 61 3f 6e raw/dkjson.lua?n
17f0: 61 6d 65 3d 33 32 61 35 33 65 36 39 33 32 36 61 ame=32a53e69326a
1800: 63 36 32 33 31 63 39 34 32 66 30 31 37 35 37 30 c6231c942f017570
1810: 30 63 62 31 31 39 61 63 38 31 30 38 20 7c 20 64 0cb119ac8108 | d
1820: 6b 6a 73 6f 6e 2e 6c 75 61 20 76 65 72 73 69 6f kjson.lua versio
1830: 6e 20 31 2e 31 5d 0d 0a 0d 0a 43 68 61 6e 67 65 n 1.1]....Change
1840: 73 20 73 69 6e 63 65 20 76 65 72 73 69 6f 6e 20 s since version
1850: 31 2e 30 3a 0d 0a 0d 0a 20 20 2a 20 20 54 68 65 1.0:.... * The
1860: 20 76 61 6c 75 65 73 20 4e 61 4e 2f 2b 49 6e 66 values NaN/+Inf
1870: 2f 2d 49 6e 66 20 61 72 65 20 72 65 63 6f 67 6e /-Inf are recogn
1880: 69 73 65 64 20 61 6e 64 20 65 6e 63 6f 64 65 64 ised and encoded
1890: 20 61 73 20 22 6e 75 6c 6c 22 20 6c 69 6b 65 20 as "null" like
18a0: 69 6e 0d 0a 20 20 20 20 20 74 68 65 20 6f 72 69 in.. the ori
18b0: 67 69 6e 61 6c 20 4a 61 76 61 53 63 72 69 70 74 ginal JavaScript
18c0: 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2e implementation.
18d0: 0d 0a 20 20 2a 20 20 52 65 61 64 20 5f 5f 74 6f .. * Read __to
18e0: 6a 73 6f 6e 20 65 76 65 6e 20 66 72 6f 6d 20 62 json even from b
18f0: 6c 6f 63 6b 65 64 20 6d 65 74 61 74 61 62 6c 65 locked metatable
1900: 73 20 74 68 72 6f 75 67 68 20 74 68 65 20 64 65 s through the de
1910: 62 75 67 20 6d 6f 64 75 6c 65 2e 0d 0a 20 20 2a bug module... *
1920: 20 20 46 69 78 65 64 20 64 65 63 6f 64 69 6e 67 Fixed decoding
1930: 20 73 69 6e 67 6c 65 20 6e 75 6d 62 65 72 73 2e single numbers.
1940: 0d 0a 20 20 2a 20 20 43 6f 72 72 65 63 74 65 64 .. * Corrected
1950: 20 74 68 65 20 72 61 6e 67 65 20 6f 66 20 65 73 the range of es
1960: 63 61 70 65 64 20 55 6e 69 63 6f 64 65 20 63 6f caped Unicode co
1970: 6e 74 72 6f 6c 20 63 68 61 72 61 63 74 65 72 73 ntrol characters
1980: 2e 0d 0a 0d 0a 3c 68 33 3e 56 65 72 73 69 6f 6e .....<h3>Version
1990: 20 32 2e 30 20 28 32 30 31 31 2d 30 35 2d 33 30 2.0 (2011-05-30
19a0: 29 3c 2f 68 33 3e 0d 0a 0d 0a 20 20 2a 20 20 44 )</h3>.... * D
19b0: 6f 77 6e 6c 6f 61 64 20 5b 2e 2f 72 61 77 2f 64 ownload [./raw/d
19c0: 6b 6a 73 6f 6e 2e 6c 75 61 3f 6e 61 6d 65 3d 33 kjson.lua?name=3
19d0: 35 36 33 30 32 39 30 65 34 33 62 33 33 32 61 38 5630290e43b332a8
19e0: 34 66 62 33 61 35 35 30 34 37 36 35 65 66 36 64 4fb3a5504765ef6d
19f0: 62 38 62 37 63 34 39 20 7c 20 64 6b 6a 73 6f 6e b8b7c49 | dkjson
1a00: 2e 6c 75 61 20 76 65 72 73 69 6f 6e 20 32 2e 30 .lua version 2.0
1a10: 5d 0d 0a 0d 0a 43 68 61 6e 67 65 73 20 73 69 6e ]....Changes sin
1a20: 63 65 20 76 65 72 73 69 6f 6e 20 31 2e 30 3a 0d ce version 1.0:.
1a30: 0a 0d 0a 20 20 2a 20 20 4f 70 74 69 6f 6e 61 6c ... * Optional
1a40: 20 4c 50 65 67 20 73 75 70 70 6f 72 74 2e 0d 0a LPeg support...
1a50: 20 20 2a 20 20 49 6e 76 61 6c 69 64 20 69 6e 70 * Invalid inp
1a60: 75 74 20 64 61 74 61 20 66 6f 72 20 65 6e 63 6f ut data for enco
1a70: 64 69 6e 67 20 72 61 69 73 65 73 20 65 72 72 6f ding raises erro
1a80: 72 73 20 69 6e 73 74 65 61 64 20 6f 66 20 72 65 rs instead of re
1a90: 74 75 72 6e 69 6e 67 20 6e 69 6c 0d 0a 20 20 20 turning nil..
1aa0: 20 20 61 6e 64 20 74 68 65 20 65 72 72 6f 72 20 and the error
1ab0: 6d 65 73 73 61 67 65 2e 20 28 49 6e 76 61 6c 69 message. (Invali
1ac0: 64 20 64 61 74 61 20 66 6f 72 20 65 6e 63 6f 64 d data for encod
1ad0: 69 6e 67 20 69 73 20 75 73 75 61 6c 6c 79 20 61 ing is usually a
1ae0: 0d 0a 20 20 20 20 20 70 72 6f 67 72 61 6d 6d 69 .. programmi
1af0: 6e 67 20 65 72 72 6f 72 2e 20 52 61 69 73 69 6e ng error. Raisin
1b00: 67 20 61 6e 20 65 72 72 6f 72 20 72 65 6d 6f 76 g an error remov
1b10: 65 73 20 74 68 65 20 77 6f 72 6b 20 6f 66 20 65 es the work of e
1b20: 78 70 6c 69 63 69 74 6c 79 0d 0a 20 20 20 20 20 xplicitly..
1b30: 63 68 65 63 6b 69 6e 67 20 74 68 65 20 72 65 73 checking the res
1b40: 75 6c 74 29 2e 0d 0a 20 20 2a 20 20 54 68 65 20 ult)... * The
1b50: 6d 65 74 61 74 61 62 6c 65 20 66 69 65 6c 64 20 metatable field
1b60: 5f 5f 6a 73 6f 6e 74 79 70 65 20 63 61 6e 20 63 __jsontype can c
1b70: 6f 6e 74 72 6f 6c 20 77 68 65 74 68 65 72 20 61 ontrol whether a
1b80: 20 4c 75 61 20 74 61 62 6c 65 20 69 73 0d 0a 20 Lua table is..
1b90: 20 20 20 20 65 6e 63 6f 64 65 64 20 61 73 20 61 encoded as a
1ba0: 20 4a 53 4f 4e 20 61 72 72 61 79 20 6f 72 20 6f JSON array or o
1bb0: 62 6a 65 63 74 2e 20 28 4d 61 69 6e 6c 79 20 75 bject. (Mainly u
1bc0: 73 65 66 75 6c 20 66 6f 72 20 65 6d 70 74 79 20 seful for empty
1bd0: 74 61 62 6c 65 73 29 2e 0d 0a 20 20 2a 20 20 57 tables)... * W
1be0: 68 65 6e 20 64 65 63 6f 64 69 6e 67 2c 20 74 77 hen decoding, tw
1bf0: 6f 20 6d 65 74 61 74 61 62 6c 65 73 20 61 72 65 o metatables are
1c00: 20 63 72 65 61 74 65 64 2e 20 4f 6e 65 20 69 73 created. One is
1c10: 20 75 73 65 64 20 74 6f 20 6d 61 72 6b 20 74 68 used to mark th
1c20: 65 20 61 72 72 61 79 73 0d 0a 20 20 20 20 20 77 e arrays.. w
1c30: 68 69 6c 65 20 74 68 65 20 6f 74 68 65 72 20 6f hile the other o
1c40: 6e 65 20 69 73 20 75 73 65 64 20 66 6f 72 20 74 ne is used for t
1c50: 68 65 20 6f 62 6a 65 63 74 73 2e 20 28 54 68 65 he objects. (The
1c60: 20 6d 65 74 61 74 61 62 6c 65 73 20 61 72 65 0d metatables are.
1c70: 0a 20 20 20 20 20 63 72 65 61 74 65 64 20 6f 6e . created on
1c80: 63 65 20 66 6f 72 20 65 61 63 68 20 64 65 63 6f ce for each deco
1c90: 64 69 6e 67 20 6f 70 65 72 61 74 69 6f 6e 20 74 ding operation t
1ca0: 6f 20 6d 61 6b 65 20 73 61 6e 64 62 6f 78 69 6e o make sandboxin
1cb0: 67 20 70 6f 73 73 69 62 6c 65 2e 0d 0a 20 20 20 g possible...
1cc0: 20 20 48 6f 77 65 76 65 72 2c 20 79 6f 75 20 63 However, you c
1cd0: 61 6e 20 73 70 65 63 69 66 79 20 79 6f 75 72 20 an specify your
1ce0: 6f 77 6e 20 6d 65 74 61 74 61 62 6c 65 73 20 61 own metatables a
1cf0: 73 20 61 72 67 75 6d 65 6e 74 73 29 2e 0d 0a 20 s arguments)...
1d00: 20 2a 20 20 54 68 65 72 65 20 61 72 65 20 6e 6f * There are no
1d10: 20 73 70 61 63 65 73 20 61 64 64 65 64 20 61 6e spaces added an
1d20: 79 20 6c 6f 6e 67 65 72 20 77 68 65 6e 20 65 6e y longer when en
1d30: 63 6f 64 69 6e 67 2e 0d 0a 20 20 2a 20 20 49 74 coding... * It
1d40: 20 69 73 20 70 6f 73 73 69 62 6c 65 20 74 6f 20 is possible to
1d50: 65 78 70 6c 69 63 69 74 6c 79 20 73 6f 72 74 20 explicitly sort
1d60: 6b 65 79 73 20 66 6f 72 20 65 6e 63 6f 64 69 6e keys for encodin
1d70: 67 20 62 79 20 70 72 6f 76 69 64 69 6e 67 20 61 g by providing a
1d80: 6e 20 61 72 72 61 79 20 77 69 74 68 20 6b 65 79 n array with key
1d90: 0d 0a 20 20 20 20 20 6e 61 6d 65 73 20 74 6f 20 .. names to
1da0: 74 68 65 20 6f 70 74 69 6f 6e 20 22 6b 65 79 6f the option "keyo
1db0: 72 64 65 72 22 20 6f 72 20 74 68 65 20 6d 65 74 rder" or the met
1dc0: 61 74 61 62 6c 65 20 66 69 65 6c 64 20 5f 5f 6a atable field __j
1dd0: 73 6f 6e 6f 72 64 65 72 2e 0d 0a 20 20 2a 20 20 sonorder... *
1de0: 54 68 65 20 76 61 6c 75 65 73 20 4e 61 4e 2f 2b The values NaN/+
1df0: 49 6e 66 2f 2d 49 6e 66 20 61 72 65 20 72 65 63 Inf/-Inf are rec
1e00: 6f 67 6e 69 73 65 64 20 61 6e 64 20 65 6e 63 6f ognised and enco
1e10: 64 65 64 20 61 73 20 22 6e 75 6c 6c 22 20 6c 69 ded as "null" li
1e20: 6b 65 20 69 6e 0d 0a 20 20 20 20 20 74 68 65 20 ke in.. the
1e30: 6f 72 69 67 69 6e 61 6c 20 4a 61 76 61 53 63 72 original JavaScr
1e40: 69 70 74 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 ipt implementati
1e50: 6f 6e 2e 0d 0a 0d 0a 3c 68 33 3e 56 65 72 73 69 on.....<h3>Versi
1e60: 6f 6e 20 31 2e 30 20 28 32 30 31 30 2d 30 38 2d on 1.0 (2010-08-
1e70: 32 38 29 3c 2f 68 33 3e 0d 0a 0d 0a 49 6e 69 74 28)</h3>....Init
1e80: 69 61 6c 20 76 65 72 73 69 6f 6e 2e 0d 0a 0d 0a ial version.....
1e90: 20 20 2a 20 20 44 6f 77 6e 6c 6f 61 64 20 5b 2e * Download [.
1ea0: 2f 72 61 77 2f 64 6b 6a 73 6f 6e 2e 6c 75 61 3f /raw/dkjson.lua?
1eb0: 6e 61 6d 65 3d 37 31 38 65 32 62 35 38 36 36 37 name=718e2b58667
1ec0: 63 32 65 66 35 34 34 66 65 64 34 65 32 38 66 63 c2ef544fed4e28fc
1ed0: 34 37 34 32 36 37 65 32 36 30 63 62 31 20 7c 20 474267e260cb1 |
1ee0: 64 6b 6a 73 6f 6e 2e 6c 75 61 20 76 65 72 73 69 dkjson.lua versi
1ef0: 6f 6e 20 31 2e 30 5d 0d 0a 0a 5a 20 30 63 63 36 on 1.0]...Z 0cc6
1f00: 35 37 65 36 38 66 30 35 36 62 38 61 34 37 66 32 57e68f056b8a47f2
1f10: 62 61 34 66 63 30 33 35 65 39 30 33 0a ba4fc035e903.