Module rsjson

Require: require("rsjson")

Index

Data

serde

Low-level serde API

Function

decode()

Deserialize a JSON string into a Lua object

encode()

Serialize a Lua object into a JSON string

from_file()

Deserialize a JSON object from a file

from_str()

Deserialize a JSON object from a string

to_file()

Serialize a Lua object to a file

to_str()

Serialize a Lua object to a string

Class

DecodeConfig

EncodeConfig

Alias

null

Represents the JSON null value. This can be used in the place of nil to represent empty values.

Api reference

rsjson.serde: table

Low-level serde API

alias rsjson.null = lightuserdata

Represents the JSON null value. This can be used in the place of nil to represent empty values.

class rsjson.EncodeConfig: userdata
indent: number

The number of prefix to indent lines

prefix: string

The string to use for indentation

sort_keys: boolean

Sort JSON keys

empty_table_as_array: boolean

Convert empty tables to empty arrays

detect_mixed_tables: boolean

Detect mixed sequence and key tables

error_unsupported: boolean

Error on unsupported types (functions, userdata, etc)

error_cycles: boolean

Error on cycles

new: fun(): rsjson.EncodeConfig
class rsjson.DecodeConfig: userdata
null: boolean

Convert nil to rsjson.null

cast_u64_to_f64: boolean

Convert u64 numbers to f64 if they overflow i64

set_array_mt: boolean

Set the metatable of JSON array tables to mlua::Lua::array_metatable

new: fun(): rsjson.DecodeConfig
rsjson.encode(obj: any, config?: rsjson.EncodeConfig): string

Serialize a Lua object into a JSON string

Parameters:

obj (any) – Any Lua object

Returns:

_1 (string) – The serialized Lua object

rsjson.decode(str: string, config?: rsjson.DecodeConfig): any

Deserialize a JSON string into a Lua object

Parameters:

str (string) – The JSON string

Returns:

_1 (any) – The deserialized JSON object

rsjson.to_file(obj: any, path: string, indent?: number): string

Serialize a Lua object to a file

Parameters:
  • obj (any) – Any Lua object

  • path (string) – The filepath to write to

  • indent? (number) – The indent level of lines

Returns:

_1 (string) – The serialized Lua object

rsjson.to_str(obj: any, indent?: number): string

Serialize a Lua object to a string

Parameters:
  • obj (any) – Any Lua object

  • indent? (number) – The indent level of lines

Returns:

_1 (string) – The serialized Lua object

rsjson.from_file(path: string): any

Deserialize a JSON object from a file

Parameters:

path (string) – The filepath to load

Returns:

_1 (any) – The deserialized JSON object

rsjson.from_str(str: string): any

Deserialize a JSON object from a string

Parameters:

str (string) – The string to load

Returns:

_1 (any) – The deserialized JSON object