> Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

---
title: JSON
icon: file-braces
---

# <ApiPageIcon icon="file-braces" />JSON

<Heading level={2} id="json-1">
  json

  <ApiTag label="object type" />
</Heading>

Encodes Lua values as JSON and decodes JSON into Lua values.

<ApiMembers>
  <ApiMember kind="fn" name="json.new" summary="`json.new` can be used to instantiate an independent copy of the Lua CJSON module. The new module has a separate persistent encoding buffer, and default settings." args="" sig="[{&#x22;s&#x22;:&#x22;json.new&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;json&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/data/json#json-1&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;json&#x22;,&#x22;k&#x22;:&#x22;class&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/data/json#json-1&#x22;}]]" />

  <ApiMember kind="fn" name="json.decode" summary="`json.decode` will deserialise any UTF-8 JSON string into a Lua value or table." args="json_text" sig="[{&#x22;s&#x22;:&#x22;json.decode&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;json_text&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;json_text&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}]}]" returns="[{&#x22;n&#x22;:&#x22;value&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]}]">
    <ApiNotes>
      UTF-16 and UTF-32 JSON strings are not supported.

      `json.decode` requires that any NULL (ASCII 0) and double quote (ASCII 34)
      characters are escaped within strings. All escape codes will be decoded and
      other bytes will be passed transparently. UTF-8 characters are not validated
      during decoding and should be checked elsewhere if required.

      JSON `null` will be converted to NULL `lightuserdata` value.

      By default, numbers incompatible with the JSON specification (infinity,
      NaN, hexadecimal) can be decoded. This default can be changed with
      `json.decode_invalid_numbers`.

      <Warning>
        Care must be taken after decoding JSON objects with numeric keys. Each
        numeric key will be stored as a Lua `string`. Any subsequent code assuming
        type `number` may break.
      </Warning>
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="json.decode_invalid_numbers" summary="Lua CJSON may generate an error when trying to decode numbers not supported by the JSON specification. *Invalid numbers* are defined as:" args="setting?" sig="[{&#x22;s&#x22;:&#x22;json.decode_invalid_numbers&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;[&#x22;},{&#x22;s&#x22;:&#x22;setting&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;setting&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}],&#x22;o&#x22;:true}]" returns="[{&#x22;n&#x22;:&#x22;setting&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}]}]">
    <ApiNotes>
      * infinity
      * not-a-number (NaN)
      * hexadecimal

      Available settings:

      * `true`: Accept and decode *invalid numbers*. This is the default setting.
      * `false`: Throw an error when *invalid numbers* are encountered.

      The current setting is always returned, and is only updated when an argument
      is provided.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="json.decode_max_depth" summary="Lua CJSON will generate an error when parsing deeply nested JSON once the maximum array/object depth has been exceeded. This check prevents unnecessarily complicated JSON from slowing down the application, or crashing the application due to a lack of process stack space." args="depth?" sig="[{&#x22;s&#x22;:&#x22;json.decode_max_depth&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;[&#x22;},{&#x22;s&#x22;:&#x22;depth&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;depth&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],&#x22;d&#x22;:&#x22;must be a positive integer.&#x22;,&#x22;o&#x22;:true}]" returns="[{&#x22;n&#x22;:&#x22;depth&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]}]">
    <ApiNotes>
      An error may be generated before the depth limit is hit if Lua is unable to
      allocate more objects on the Lua stack.

      By default, Lua CJSON will reject JSON with arrays and/or objects nested
      more than 1000 levels deep.

      The current setting is always returned, and is only updated when an argument
      is provided.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="json.encode" summary="`json.encode` will serialise a Lua value into a string containing the JSON representation." args="value" sig="[{&#x22;s&#x22;:&#x22;json.encode&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;value&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;unknown&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;value&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;unknown&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]}]" returns="[{&#x22;n&#x22;:&#x22;json_text&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;string&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#string&#x22;}]}]">
    <ApiNotes>
      `json.encode` supports the following types:

      * `boolean`
      * `lightuserdata` (NULL value only)
      * `nil`
      * `number`
      * `string`
      * `table`

      The remaining Lua types will generate an error:

      * `function`
      * `lightuserdata` (non-NULL values)
      * `thread`
      * `userdata`

      By default, numbers are encoded with 14 significant digits. Refer to
      `json.encode_number_precision` for details.

      Lua CJSON will escape the following characters within each UTF-8 string:

      * Control characters (ASCII 0 - 31)
      * Double quote (ASCII 34)
      * Forward slash (ASCII 47)
      * Backslash (ASCII 92)
      * Delete (ASCII 127)

      All other bytes are passed transparently.

      <Warning>
        Lua CJSON will successfully encode/decode binary strings, but this is
        technically not supported by JSON and may not be compatible with other
        JSON libraries. To ensure the output is valid JSON, applications should
        ensure all Lua strings passed to `json.encode` are UTF-8.
      </Warning>

      Lua CJSON uses a heuristic to determine whether to encode a Lua table as a
      JSON array or an object. A Lua table with only positive integer keys of type
      `number` will be encoded as a JSON array. All other tables will be encoded
      as a JSON object.

      Lua CJSON does not use metamethods when serialising tables.

      * `rawget` is used to iterate over Lua arrays
      * `next` is used to iterate over Lua objects

      Lua arrays with missing entries (*sparse arrays*) may optionally be encoded
      in several different ways. Refer to `json.encode_sparse_array` for details.

      JSON object keys are always strings. Hence `json.encode` only supports
      table keys which are type `number` or `string`. All other types will
      generate an error.

      By default, encoding the following Lua values will generate errors:

      * Numbers incompatible with the JSON specification (infinity, NaN)
      * Tables nested more than 1000 levels deep
      * Excessively sparse Lua arrays

      These defaults can be changed with:

      * `json.encode_invalid_numbers`
      * `json.encode_max_depth`
      * `json.encode_sparse_array`
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="json.encode_invalid_numbers" summary="Lua CJSON may generate an error when encoding floating point numbers not supported by the JSON specification (*invalid numbers*):" args="setting?" sig="[{&#x22;s&#x22;:&#x22;json.encode_invalid_numbers&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;[&#x22;},{&#x22;s&#x22;:&#x22;setting&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;true&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;},{&#x22;s&#x22;:&#x22;|&#x22;},{&#x22;s&#x22;:&#x22;false&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;},{&#x22;s&#x22;:&#x22;|&#x22;},{&#x22;s&#x22;:&#x22;\&#x22;&#x22;},{&#x22;s&#x22;:&#x22;null&#x22;},{&#x22;s&#x22;:&#x22;\&#x22;&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;true&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;},{&#x22;s&#x22;:&#x22;|&#x22;},{&#x22;s&#x22;:&#x22;false&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;},{&#x22;s&#x22;:&#x22;|&#x22;},{&#x22;s&#x22;:&#x22;\&#x22;&#x22;},{&#x22;s&#x22;:&#x22;null&#x22;},{&#x22;s&#x22;:&#x22;\&#x22;&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;true&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;},{&#x22;s&#x22;:&#x22;|&#x22;},{&#x22;s&#x22;:&#x22;false&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;},{&#x22;s&#x22;:&#x22;|&#x22;},{&#x22;s&#x22;:&#x22;\&#x22;&#x22;},{&#x22;s&#x22;:&#x22;null&#x22;},{&#x22;s&#x22;:&#x22;\&#x22;&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;setting&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;true&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;},{&#x22;s&#x22;:&#x22;|&#x22;},{&#x22;s&#x22;:&#x22;false&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;},{&#x22;s&#x22;:&#x22;|&#x22;},{&#x22;s&#x22;:&#x22;\&#x22;&#x22;},{&#x22;s&#x22;:&#x22;null&#x22;},{&#x22;s&#x22;:&#x22;\&#x22;&#x22;}],&#x22;o&#x22;:true}]" returns="[{&#x22;n&#x22;:&#x22;setting&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;true&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;},{&#x22;s&#x22;:&#x22;|&#x22;},{&#x22;s&#x22;:&#x22;false&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;},{&#x22;s&#x22;:&#x22;|&#x22;},{&#x22;s&#x22;:&#x22;\&#x22;&#x22;},{&#x22;s&#x22;:&#x22;null&#x22;},{&#x22;s&#x22;:&#x22;\&#x22;&#x22;}]}]">
    <ApiNotes>
      * infinity
      * not-a-number (NaN)

      Available settings:

      * `true`: Allow *invalid numbers* to be encoded. This will generate
        non-standard JSON, but this output is supported by some libraries.

      * `"null"`: Encode *invalid numbers* as a JSON `null` value. This allows
        infinity and NaN to be encoded into valid JSON.

      * `false`: Throw an error when attempting to encode *invalid numbers*. This
        is the default setting.

      The current setting is always returned, and is only updated when an argument
      is provided.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="json.encode_keep_buffer" summary="Lua CJSON can reuse the JSON encoding buffer to improve performance." args="keep?" sig="[{&#x22;s&#x22;:&#x22;json.encode_keep_buffer&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;[&#x22;},{&#x22;s&#x22;:&#x22;keep&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;keep&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}],&#x22;o&#x22;:true}]" returns="[{&#x22;n&#x22;:&#x22;keep&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}]}]">
    <ApiNotes>
      Available settings:

      * `true`: The buffer will grow to the largest size required and is not freed
        until the Lua CJSON module is garbage collected. This is the default
        setting.

      * `false`: Free the encode buffer after each call to `json.encode`.

      The current setting is always returned, and is only updated when an argument
      is provided.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="json.encode_max_depth" summary="Once the maximum table depth has been exceeded Lua CJSON will generate an error. This prevents deeply nested or recursive data structure from crashing the application." args="depth?" sig="[{&#x22;s&#x22;:&#x22;json.encode_max_depth&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;[&#x22;},{&#x22;s&#x22;:&#x22;depth&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;depth&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],&#x22;d&#x22;:&#x22;must be a positive integer.&#x22;,&#x22;o&#x22;:true}]" returns="[{&#x22;n&#x22;:&#x22;depth&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]}]">
    <ApiNotes>
      By default, Lua CJSON will generate an error when trying to encode data
      structures with more than 1000 nested tables.

      The current setting is always returned, and is only updated when an argument
      is provided.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="json.encode_number_precision" summary="Sets the number of significant digits used when encoding numbers. Lower values reduce precision." args="precision?" sig="[{&#x22;s&#x22;:&#x22;json.encode_number_precision&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;[&#x22;},{&#x22;s&#x22;:&#x22;precision&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;precision&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],&#x22;o&#x22;:true}]" returns="[{&#x22;n&#x22;:&#x22;precision&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]}]">
    <ApiNotes>
      By default, Lua CJSON will output 14 significant digits when converting a
      number to text.

      The current setting is always returned, and is only updated when an argument
      is provided.
    </ApiNotes>
  </ApiMember>

  <ApiMember kind="fn" name="json.encode_sparse_array" summary="Lua CJSON classifies a Lua table into one of three kinds when encoding a JSON array. This is determined by the number of values missing from the Lua array as follows:" args="convert?, ratio?, safe?" sig="[{&#x22;s&#x22;:&#x22;json.encode_sparse_array&#x22;},{&#x22;s&#x22;:&#x22;(&#x22;},{&#x22;s&#x22;:&#x22;[&#x22;},{&#x22;s&#x22;:&#x22;convert&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;ratio&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;safe&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;]&#x22;},{&#x22;s&#x22;:&#x22;)&#x22;},{&#x22;s&#x22;:&#x22;: &#x22;},{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;},{&#x22;s&#x22;:&#x22;, &#x22;},{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]" ret="[[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}],[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]]" params="[{&#x22;n&#x22;:&#x22;convert&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}],&#x22;o&#x22;:true},{&#x22;n&#x22;:&#x22;ratio&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],&#x22;d&#x22;:&#x22;must be a non-negative integer.&#x22;,&#x22;o&#x22;:true},{&#x22;n&#x22;:&#x22;safe&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}],&#x22;d&#x22;:&#x22;must be a positive integer.&#x22;,&#x22;o&#x22;:true}]" returns="[{&#x22;n&#x22;:&#x22;convert&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;boolean&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#boolean&#x22;}]},{&#x22;n&#x22;:&#x22;ratio&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]},{&#x22;n&#x22;:&#x22;safe&#x22;,&#x22;t&#x22;:[{&#x22;s&#x22;:&#x22;integer&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;,&#x22;h&#x22;:&#x22;/cs2/api_reference/lua/base#integer&#x22;}]}]">
    <ApiNotes>
      * **Normal**: All values are available.
      * **Sparse**: At least one value is missing.
      * **Excessively sparse**: The number of values missing exceeds the
        configured ratio.

      Lua CJSON encodes sparse Lua arrays as JSON arrays using JSON `null` for the
      missing entries.

      An array is excessively sparse when all the following conditions are met:

      * `ratio > 0`
      * `maximum_index > safe`
      * `maximum_index > item_count * ratio`

      Lua CJSON will never consider an array to be *excessively sparse* when
      `ratio == 0`. The `safe` limit ensures that small Lua arrays are always
      encoded as sparse arrays.

      By default, attempting to encode an *excessively sparse* array will generate
      an error. If `convert` is set to `true`, *excessively sparse* arrays will be
      converted to a JSON object.

      The current settings are always returned. A particular setting is only
      changed when the argument is provided (non-`nil`).
    </ApiNotes>
  </ApiMember>
</ApiMembers>
