1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
--- SPDX-License-Identifier: MIT
---@meta rsjson
local rsjson =
--- Represents the JSON `null` value.
--- This can be used in the place of
--- `nil` to represent empty values.
---
---@class rsjson.null: lightuserdata
rsjson. = nil
--- A metatable attachable to a Lua table to systematically encode
--- it as Array (instead of Map). As a result, encoded Array will
--- contain only sequence part of the table, with the same length
--- as the # operator on that table.
---
---@class rsjson.array_mt: table
rsjson. = nil
---@class (exact) rsjson.EncodeConfig: userdata
---
---@field indent number The number of `prefix` to indent lines
---@field prefix string The string to use for indentation
---@field sort_keys boolean Sort JSON keys
---@field empty_table_as_array boolean Convert empty tables to empty arrays
---@field detect_mixed_tables boolean Detect mixed sequence and key tables
---@field error_unsupported boolean Error on unsupported types (functions, userdata, etc)
---@field error_cycles boolean Error on cycles
rsjson. =
--- Create a new `rsjson.EncodeConfig`
---
---@return rsjson.EncodeConfig
---@class (exact) rsjson.DecodeConfig: userdata
---
---@field null boolean Convert `nil` to `rsjson.null`
---@field cast_u64_to_f64 boolean Convert u64 numbers to f64 if they overflow i64
---@field set_array_mt boolean Set the metatable of JSON array tables to `mlua::Lua::array_metatable`
rsjson. =
--- Create a new `rsjson.DecodeConfig`
---
---@return rsjson.DecodeConfig
--- Serialize a Lua object into a JSON string
---
---@param obj any Any Lua object
---@param config? rsjson.EncodeConfig
---
---@return string # The serialized Lua object
--- Deserialize a JSON string into a Lua object
---
---@param str string The JSON string
---@param config? rsjson.DecodeConfig
---
---@return any # The deserialized JSON object
return rsjson