File: LuaJSON.txt

package info (click to toggle)
lua-json 1.3.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 688 kB
  • sloc: makefile: 71; php: 3
file content (213 lines) | stat: -rw-r--r-- 6,070 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
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
LuaJSON(3)
==========
:Author: Thomas Harning
:Email:  harningt@gmail.com
:Date:   2009/04/29

NAME
----
luajson - JSON encoder/decoder for Lua

SYNOPSIS
--------
local json = require("json")

json.decode("json-string" [, parameters])

json.decode.getDecoder(parameters)

json.encode(lua_value [, parameters])

json.encode.getEncoder(parameters)

DESCRIPTION
-----------
json.decode("json-string" [, parameters])::
    Obtains a JSON decoder using `getDecoder` with the parameters specified,
    then performs the decoding operation.

json.encode(lua_value [, parameters])::
    Obtains a JSON encoder using `getEncoder` with the parameters specified,
    then performs the encoding operation.

json.decode.getDecoder(parameters)::
    Obtains a JSON decoder configured with the given parameters or defaults.

json.encode.getEncoder(parameters)::
    Obtains a JSON encoder configured with the given parameters or defaults.

json.encode.strict::
    A default parameter specification containing 'strict' rules for encoding

json.decode.strict::
    A default parameter specification containing 'strict' rules for decoding

=== COMMON PARAMETERS

initialObject : boolean::
    Specifies if the outermost element be an array or object

allowUndefined : boolean::
    Specifies if 'undefined' is an allowed value

null : any::
    Placeholder object for null values

undefined : any::
    Placeholder for undefined values

number.nan : boolean::
    Specifies if NaN is an allowed value

number.inf : boolean::
    Specifies if +/-Infinity is an allowed value

=== ENCODER-SPECIFIC PARAMETERS

preProcess : `function(object)`::
    Called for every value to be encoded, optionally altering.
    If returns `nil` then no value change occurs.

output : function::
    Function that returns an encoder specification (TBD), if null
    default used that returns a string.

array.isArray : `function(object)`::
    If `true`/`false` returned, then the value is authoritatively
    an array or not

strings.xEncode : boolean::
    Specifies if binary values are to be encoded with \xNN rather than \uNNNN

strings.encodeSet : string::
    http://www.lua.org/manual/5.1/manual.html#5.4.1[gmatch-style] set of
    characters that need to be escaped (to be contained in `[]`)

strings.encodeSetAppend : string::
    Set of characters that need to be escaped (to be contained in `[]`).
    Appended to the current encodeSet.

==== Default Configuration
[source,lua]
----
array.isArray == json-util's isArray implementation
allowUndefined = true
number.nan = true
number.inf = true
strings.xEncode = false
strings.encodeSet = '\\"/%z\1-\031'
----

==== Strict Configuration
[source,lua]
----
initialObject = true
allowUndefined = false
number.nan = false
number.inf = false
----

=== DECODER-SPECIFIC PARAMETERS

unicodeWhitespace : boolean::
    Specifies if unicode whitespace characters are counted

array.allowEmptyElement / calls.allowEmptyElement / object.allowEmptyElement : boolean::
	Specifies if missing values are allowed, replacing them with the value of 'undefined' or 'null' if undefined not allowed.
	Example cases:
		[1,, 3] ==> { 1, json.util.undefined, 3 }
		{ x: }  ==> { x = json.util.undefined }
		call(1,, 3) ==> call(1, json.util.undefined, 3)

array.trailingComma / calls.trailingComma / object.trailingComma : boolean::
    Specifies if extraneous trailing commas are ignored in declaration

calls.defs : map<string | LPEG, function | boolean>::
    Defines set of specifically permitted function definitions.
    If boolean value, determines if allowed or not, decoded as a call object.
    Function return-value is the decoded result.
    Function definition:  `function(name, [arguments])` : output-value

calls.allowUndefined : boolean::
    Specifies if undefined call definitions are decoded as call objects.

number.frac : boolean::
    Specifies if numbers can have a decimal component (ex: `.01`)

number.exp : boolean::
    Specifies if exponents are allowed (ex: `1e2`)

number.hex : boolean::
    Specifies if hexadecimal numbers are allowed (ex: `0xDEADBEEF`)

object.number : boolean::
    Specifies if numbers can be object keys

object.identifier : boolean::
    Specifies if unquoted 'identifiers' can be object keys (matching `[A-Za-z_][A-Za-z0-9_]*`)

strings.badChars : string::
    Set of characters that should not be present in a string

strings.additionalEscapes : LPeg expression::
    LPeg expression to handle output (ex: `lpeg.C(1)` would take `\k` and spit out `k`)

strings.escapeCheck : non-consuming LPeg expression::
    LPeg expression to check if a given character is allowed to be an escape value

strings.decodeUnicode::
    `function (XX, YY)` handling \uXXYY situation to output decoded unicode sequence

strings.strict_quotes : boolean::
    Specifies if the `'` character is considered a quoting specifier

==== Default configuration

[source,lua]
----
unicodeWhitespace = true
initialObject = false
allowUndefined = true
array.trailingComma = true
number.frac = true
number.exp = true
number.hex = false
object.number = true
object.identifier = true
object.trailingComma = true
strings.badChars = '' -- No characters considered bad in a string
strings.additionalEscapes = false, -- disallow untranslated escapes
strings.escapeCheck = #lpeg.S('bfnrtv/\\"xu\'z'),
strings.decodeUnicode = utf8DecodeUnicode,
strings.strict_quotes = false
----

==== Strict configuration

[source,lua]
----
initialObject = true
allowUndefined = false
array.trailingComma = false
object.identifier = false
object.trailingComma = false
strings.badChars = '\b\f\n\r\t\v'
strings.additionalEscapes = false -- no additional escapes
strings.escapeCheck = #lpeg.S('bfnrtv/\\"u') --only these are allowed to be escaped
strings.strict_quotes = true
----

AUTHOR
------
Written by Thomas Harning Jr., <harningt@gmail.com>

REFERENCES
----------
http://www.inf.puc-rio.br/~roberto/lpeg[LPeg]

http://json.org[JSON]

COPYING
-------
Copyright (C) 2008-2009 Thomas Harning Jr.  Free use of this software is granted
under the terms of the MIT license.