Module JSON

Base Class for all JSON elements

Functions

.array (arr[, ...]) Create a new array.
.object (obj[, ...]) Create a new object.
.parse (elm) Serialize a lua json element to json string.
.parse_lua (table) Serialize a lua table to json string.
.stringify (elm) Serialize lua json element to json string.
.stringify_lua (elm) Serialize lua json object to json string.
.parse_lua (tname, t) Convert a lua table to a lua json element.
.tolua (tname, elm) Convert a lua json element to a table.


Functions

Methods
.array (arr[, ...])
Create a new array.

Parameters:

  • arr array name
  • ... elements (optional)

Returns:

    an initialized lua json array.

Usage:

    local a = JSON.array(a, 1,2,3.45,"test",true,null)
    print(a[0])  --> 1
    print(a[2])  --> 3.45
    print(a[#a-1]) --> null
.object (obj[, ...])
Create a new object.

Parameters:

  • obj object name
  • ... key value pair/s (optional)

Returns:

    an initialized lua json object

Usage:

    local o = JSON.object(o, "test","obj", "age",99, "root",null)
    print(o.test) --> obj
    print(o.age)  --> 99
    print(o.root) --> null
.parse (elm)
Serialize a lua json element to json string.

Parameters:

  • elm lua table

Returns:

    a valid json element

Usage:

    local a = JSON.parse('[1,2,3.45,true]')
    print(a:tojson()) --> [1,2,3.45,true]
    print(a[0])  --> 1
.parse_lua (table)
Serialize a lua table to json string.

Parameters:

  • table lua table

Returns:

    a valid json representation of the table.

Usage:

    local t = {1,2,3.45,"test",true}
    print(t) --> table: 0x5c92968f1c90
    
    local ta = JSON.parse_lua(ta, t)
    print(ta) --> array: 0x5c92968f09a8
    print(ta[0])  --> 1
    print(ta[2])  --> 3.45
    print(ta[#ta]) --> true
.stringify (elm)
Serialize lua json element to json string.

Parameters:

  • elm lua json element

Returns:

    a valid json representation of the lua json element.

Usage:

    local a = JSON.parse('[1,2,3.45,true]')
    print(a:tojson()) --> [1,2,3.45,true]
    local json_a = JSON.stringify(a)
    print(json_a) --> [1,2,3.45,"test",true]
    
.stringify_lua (elm)
Serialize lua json object to json string.

Parameters:

  • elm lua json element

Returns:

    a valid json representation of the lua json element.

Usage:

    local t = {1,2,3.45,"test",true}
    print(t) --> table: 0x5c92968f1c90
    
    local json_a = JSON.stringify_lua(t)
    print(json_a) --> [1,2,3.45,"test",true]
.parse_lua (tname, t)
Convert a lua table to a lua json element.

Parameters:

  • tname name of new element
  • t lua table

Returns:

    an initialized lua json array or object.

Usage:

    local t = {1,2,3.45,"test",true}
    print(t) --> table: 0x5c92968f1c90
    
    local ta = JSON.parse_lua(ta, t)
    print(ta) --> array: 0x5c92968f09a8
    print(ta[0])  --> 1
    print(ta[2])  --> 3.45
    print(ta[#ta]) --> true
.tolua (tname, elm)
Convert a lua json element to a table.

Parameters:

  • tname name of new element
  • elm lua json element

Returns:

    lua table
generated by LDoc 1.5.0 Last updated 2026-05-09 15:28:03