Skip to main content
Parse, encode, inspect, and transform JSON.

Available functions

json.array

Creates a new table marked as a JSON array for json.encode, copying the 1.#source sequence when a source table is provided.

json.clone

Clones a value by encoding it with json.encode semantics and decoding the generated JSON back into Lua values.

json.decode

Parses a JSON string with Real’s JSON parser and returns the decoded Lua value, marking decoded arrays and objects for the JSON helpers.

json.decodeSafe

Parses JSON with the same parsing behavior as json.decode and returns a success flag instead of throwing for parse errors.

json.encode

Serializes a Lua value to a JSON string as JSON. json.stringify is registered to the same function.

json.encodePretty

Serializes a Lua value to a readable formatted JSON string as JSON. json.pretty is registered to the same function.

json.escape

Escapes a string using Real’s JSON string escaping rules and returns the escaped content without surrounding quotes.

json.format

Parses a JSON string and re-encodes it as readable formatted JSON using Real’s JSON parser and encoder.

json.getPath

Reads a nested value from a table using a dotted string path or an array table of keys.

json.isArray

Returns whether a value is treated as a JSON array by Real’s JSON table detection.

json.isNull

Returns whether a value is Real’s JSON null sentinel, json.null.

json.isObject

Returns whether a value is treated as a JSON object by Real’s JSON table detection.

json.keys

Returns the visible keys of a table in a new table marked as a JSON array.

json.minify

Parses a JSON string and re-encodes it with Real’s default non-pretty JSON encoder output.

json.object

Creates a new table marked as a JSON object so Real’s JSON encoder treats it as an object.

json.parse

Parses a JSON string like json.decode.

json.pretty

Serializes a Lua value to a readable formatted JSON string like json.encodePretty.

json.quote

Escapes a string using Real’s JSON string escaping rules and returns a complete quoted JSON string literal.

json.stringify

Serializes a Lua value to a JSON string like json.encode.

json.tryDecode

Attempts to parse a JSON string like json.decodeSafe and returns status values for parse errors.

json.type

Returns a string type name for a value. json.null returns “null”. Tables return “array” or “object” using the same table classification as json.isArray and json.isObject. Other values return the runtime Lua type name result.

json.unescape

Decodes JSON string escape sequences from escaped string content or from a complete quoted JSON string literal. The input is parsed with the JSON string parser, not as a full JSON document.

json.validate

Validates a JSON string by parsing one complete JSON value. On success it returns only true. On parse failure it returns false plus parser error details.

json.values

Returns the direct values from a table in a new JSON array table. JSON metadata entries are not included.