Library json

Library methods for handling JSON data. It handles JSON encoding and decoding according to RFC 4627.

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.

Authors:

  • Martin Holst Swende
  • David Fifield
  • Patrick Donnelly

Copyright © Same as Nmap--See https://nmap.org/book/man-legal.html

Source: https://svn.nmap.org/nmap/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

make_object (t)

Makes a table be treated as a JSON Object when generating JSON

parse (data)

Parses JSON data into a Lua object.

typeof (var)

Checks what JSON type a variable will be treated as when generating JSON

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.

Parameters

t
a table to be treated as an array
make_object (t)

Makes a table be treated as a JSON Object when generating JSON

Parameters

t
a table to be treated as an object
parse (data)

Parses JSON data into a Lua object.

This is the method you probably want to use if you use this library from a script.

Parameters

data
a json string

Return values:

  1. status true if ok, false if bad
  2. an object representing the json, or error message
typeof (var)

Checks what JSON type a variable will be treated as when generating JSON

Parameters

var
a variable to inspect

Return value:

a string containing the JSON type. Valid values are "array", "object", "number", "string", "boolean", and "null"