json
local json = require("@std/json")WARNING
These APIs are still open to future evolution. In new major versions, they may change in backwards incompatible ways.
Summary
| Entry | Description |
|---|---|
| Array | A JSON array: a table with integer keys. |
| Object | A JSON object: a table with string keys. |
| Value | Any JSON value: null, a number, string, boolean, array, or object. |
| asArray | Returns value as an Array if it is a JSON array, or nil otherwise. |
| asObject | Returns value as an Object if it is a JSON object, or nil otherwise. |
| deserialize | Parses a JSON string and returns the corresponding Luau value. Returns json.null for a JSON null literal; compare with json.null rather than nil to check for null. |
| object | Creates a JSON Object from props. Use this to distinguish an empty object {} from an empty array when serializing. |
| serialize | Serializes value to a JSON string. If prettyPrint is true, the output is indented for readability. |
Types
Array
A JSON array: a table with integer keys.
type Array = { [number]: Value }Object
A JSON object: a table with string keys.
type Object = { [string]: Value }Value
Any JSON value: null, a number, string, boolean, array, or object.
type Value = nil | number | string | boolean | Array | ObjectFunctions and Properties
json.asArray
Returns value as an Array if it is a JSON array, or nil otherwise.
(value: Value) -> Array?json.asObject
Returns value as an Object if it is a JSON object, or nil otherwise.
(value: Value) -> Object?json.deserialize
Parses a JSON string and returns the corresponding Luau value. Returns json.null for a JSON null literal; compare with json.null rather than nil to check for null.
(src: string) -> (Array | Object | boolean | number | string)?json.object
Creates a JSON Object from props. Use this to distinguish an empty object {} from an empty array when serializing.
(props: { [string]: Value }) -> Objectjson.serialize
Serializes value to a JSON string. If prettyPrint is true, the output is indented for readability.
(value: Value, prettyPrint: boolean?) -> string