api/LibJSON-1.0

LibJSON.Deserialize(value)

Deserialize a JSON object into a lua object This will error if the JSON object is malformed.

Parameters

value
a string, number, boolean, or nil (or LibJSON.Null()), or a table consisting of those

Return value

a lua object, either a table, string, number, boolean, or nil

Usage

LibJSON.Deserialize("1234") == 1234
LibJSON.Deserialize("1.234e+53") == 1234e50
LibJSON.Deserialize('"Hello, friend"') == "Hello, friend"
LibJSON.Deserialize('[1, 2, 3]') => { 1, 2, 3 }
LibJSON.Deserialize('[1, null, 3]') => { [1] = 1, [3] = 3 }
LibJSON.Deserialize('{"one":"two"}') => { one = "two" }
LibJSON.Deserialize('"\u00DCberfantastisch"') => "\195\156berfantastisch"
LibJSON.Deserialize('[1, /* a comment */ 2]') => { 1, 2 }
LibJSON.Deserialize('true') => true
LibJSON.Deserialize('false') => false
LibJSON.Deserialize('null') => nil


LibJSON.Null()

Return a proxy object that will serialize to null.

Return value

a proxy object

Usage

LibJSON.Serialize(LibJSON.Null()) == "null"
LibJSON.Serialize({1, LibJSON.Null(), 3}) == "[1,null,3]"


LibJSON.Serialize(value)

Serialize an object to LibJSON This will error if a function, userdata, or thread is passed in.
This will also error if a non-UTF-8 string is passed in.

Parameters

value
a serialized JSON object

Return value

a string with the serialized data in it

Usage

LibJSON.Serialize(1234) == "1234"
LibJSON.Serialize(1234e50) == "1.234e+53"
LibJSON.Serialize("Hello, friend") == '"Hello, friend"'
LibJSON.Serialize({ 1, 2, 3 }) == "[1,2,3]"
LibJSON.Serialize({ one = 1, two = 2 }) == '{"one":1,"two":2}'
LibJSON.Serialize("\195\156berfantastisch") == '"\u00DCberfantastisch"'
LibJSON.Serialize(nil) == 'null'
LibJSON.Serialize(true) == 'true'
LibJSON.Serialize() == 'false'
LibJSON.Serialize({[4] = "Hello"}) == '[null,null,null,"Hello"]'



Comments

Posts Quoted:
Reply
Clear All Quotes