From baa727de93db009f90d70a80a9861758a24eae77 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 5 Nov 2019 10:27:59 +0100 Subject: docs: rename documentation folder to docs Signed-off-by: Jo-Philipp Wich --- docs/api/modules/luci.jsonc.parser.html | 491 ++++++++++++++++++++++++++++++++ 1 file changed, 491 insertions(+) create mode 100644 docs/api/modules/luci.jsonc.parser.html (limited to 'docs/api/modules/luci.jsonc.parser.html') diff --git a/docs/api/modules/luci.jsonc.parser.html b/docs/api/modules/luci.jsonc.parser.html new file mode 100644 index 0000000000..709cb9afc5 --- /dev/null +++ b/docs/api/modules/luci.jsonc.parser.html @@ -0,0 +1,491 @@ + + + + Reference + + + + + +
+ +
+ +
+
+
+ +
+ + + +
+ +

Object Instance luci.jsonc.parser

+ +

+ LuCI JSON parser instance. + A JSON parser instance is useful to parse JSON data chunk by chunk, without + the need to assemble all data in advance.

+ + + + + + + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
parser:parse (json) + +Parses one chunk of JSON data.
parser:get () + +Convert parsed JSON data into Lua table.
parser:set (data) + +Put Lua data into the parser.
parser:sink () + +Generate an ltn12-compatible sink.
parser:stringify (pretty) + +Serialize current parser state as JSON.
+ + + + + + +
+
+ + +

Functions

+
+ + + +
parser:parse (json)
+
+ + +Parses one chunk of JSON data. + + + +

Parameters

+
    + +
  • + json: String containing the JSON fragment to parse +
  • + +
+ + + + +

Usage:

+
parser = luci.jsonc.new() 
+ 
+while true do 
+	chunk = ...  -- fetch a cunk of data, e.g. from a socket 
+	finish, errmsg = parser.parse(chunk) 
+ 
+	if finish == nil then 
+		error("Cannot parse JSON: " .. errmsg) 
+	end 
+ 
+	if finish == true then 
+		break 
+	end 
+end
+ + + +

Return value:

+
    +
  • true if a complete JSON object has been parsed and no further input is + expected.
  • +
  • false if further input is required
  • +
  • nil if an error was encountered while parsing the current chunk. + In this case a string describing the parse error is returned as second + value.
+ + + +

See also:

+ + +
+ + + + +
parser:get ()
+
+ + +Convert parsed JSON data into Lua table. + + + + + + +

Usage:

+
parser = luci.jsonc.new() 
+parser:parse('{ "example": "test" }') 
+ 
+data = parser:get() 
+print(data.example)  -- "test"
+ + + +

Return value:

+Parsed JSON object converted into a Lua table or nil if the parser + didn't finish or encountered an error. + + + +

See also:

+ + +
+ + + + +
parser:set (data)
+
+ + +Put Lua data into the parser. + + + +

Parameters

+
    + +
  • + data: Lua data to put into the parser object. The data is converted to an + internal JSON representation that can be dumped with stringify(). + The conversion follows the rules described in luci.jsonc.stringify. +
  • + +
+ + + + +

Usage:

+
parser = luci.jsonc.new() 
+parser:set({ "some", "data" })
+ + + +

Return value:

+Nothing is returned. + + + +

See also:

+ + +
+ + + + +
parser:sink ()
+
+ + +Generate an ltn12-compatible sink. + + + + + + +

Usage:

+
parser = luci.jsonc.new() 
+ltn12.pump.all(ltn12.source.file(io.input()), parser:sink()) 
+print(parser:get())
+ + + +

Return value:

+Returns a function that can be used as an ltn12 sink. + + + +
+ + + + +
parser:stringify (pretty)
+
+ + +Serialize current parser state as JSON. + + + +

Parameters

+
    + +
  • + pretty: A boolean value indicating whether the resulting JSON should be pretty printed. +
  • + +
+ + + + +

Usage:

+
parser = luci.jsonc.new() 
+parser:parse('{ "example": "test" }') 
+print(parser:serialize())  -- '{"example":"test"}'
+ + + +

Return value:

+Returns the serialized JSON data of this parser instance. + + + +
+ + +
+ + + + + +
+ +
+ +
+

Valid XHTML 1.0!

+
+ +
+ + -- cgit v1.2.3