Library json
Library methods for handling JSON data. It handles JSON encoding and decoding according to RFC 4627.
There is a test section at the bottom which shows some example
parsing. If you want to parse JSON, you can test it by pasting sample JSON
into the TESTS table and run the test method
There is a straightforward mapping between JSON and Lua data types. One
exception is JSON NULL, which is not the same as Lua
nil. (A better match for Lua nil is JavaScript
undefined.) NULL values in JSON are represented by
the special value json.NULL.
Author:
| Martin Holst Swende |
Copyright© Same as Nmap--See http://nmap.org/book/man-legal.html
Source: http://nmap.org/svn/nselib/json.lua
Functions
| generate (obj) |
Creates json data from an object |
| make_array (t) |
Makes a table be treated as a JSON Array when generating JSON A table treated as an Array has all non-number indices ignored. () param t a table to be treated as an array |
| make_object (t) |
Makes a table be treated as a JSON Object when generating JSON A table treated as an Object has all non-number indices ignored. () param t a table to be treated as an object |
| parse (data) |
Parses json data into an object form This is the method you probably want to use if you use this library from a script. |
| typeof (var) |
Checks what JSON type a variable will be treated as when generating JSON () param var a variable to inspect () return a string containing the JSON type. Valid values are "array", "object", "number", "string", "boolean", and "null" |
Functions
- generate (obj)
-
Creates json data from an object
Parameters
- obj: a table containing data
Return value:
a string containing valid json - make_array (t)
-
Makes a table be treated as a JSON Array when generating JSON A table treated as an Array has all non-number indices ignored. () param t a table to be treated as an array
Parameters
- t:
- make_object (t)
-
Makes a table be treated as a JSON Object when generating JSON A table treated as an Object has all non-number indices ignored. () param t a table to be treated as an object
Parameters
- t:
- parse (data)
-
Parses json data into an object form This is the method you probably want to use if you use this library from a script.
Parameters
- data: a json string
Return values:
- status true if ok, false if bad
- an object representing the json, or error message
- typeof (var)
-
Checks what JSON type a variable will be treated as when generating JSON () param var a variable to inspect () return a string containing the JSON type. Valid values are "array", "object", "number", "string", "boolean", and "null"
Parameters
- var:


