> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# json.stringify

> Serialisiert einen Lua value mit derselben function wie json.encode zu einem JSON string.

<div className="real-function-page">
  ```lua theme={null}
  json.stringify(value: any, options?: EncodeOptions): string
  ```

  ## Argumente

  <ParamField path={"value"} type={"any"} required>
    Value, der encoded wird. nil, booleans, numbers, strings, tables und json.null werden direkt behandelt. Unsupported Lua types werden als null encoded, ausser errorOnUnsupported ist true.
  </ParamField>

  <ParamField path={"options"} type={"EncodeOptions"}>
    Optional encode options. Ein boolean toggelt pretty output. Eine number aktiviert pretty output mit so vielen spaces, geclamped auf 0.16. Ein string aktiviert pretty output mit diesem indent. Eine table kann pretty, sortKeys, emptyTableAsArray, errorOnUnsupported, encodeInvalidNumbersAsNull, maxDepth und indent setzen.
  </ParamField>

  ## Rückgaben

  <ResponseField name={"json"} type={"string"}>
    Encoded JSON string. Encoding errors werden als Luau errors geworfen.
  </ResponseField>

  ## Typen

  ### EncodeOptions

  Steuert die JSON-Serialisierung und -Formatierung.

  | Name                         | Type      | Required | Beschreibung                                                           |
  | ---------------------------- | --------- | -------- | ---------------------------------------------------------------------- |
  | `pretty`                     | `boolean` | No       | Ermöglicht eine formatierte, mehrzeilige JSON-Ausgabe.                 |
  | `sortKeys`                   | `boolean` | No       | Sortiert Objektschlüssel vor der Codierung.                            |
  | `emptyTableAsArray`          | `boolean` | No       | Kodiert eine leere Tabelle als Array statt als Objekt.                 |
  | `errorOnUnsupported`         | `boolean` | No       | Löst einen Fehler aus, anstatt nicht unterstützte Werte zu ersetzen.   |
  | `encodeInvalidNumbersAsNull` | `boolean` | No       | Kodiert NaN und unendliche Zahlen als JSON-Null.                       |
  | `maxDepth`                   | `integer` | No       | Legt die maximale Verschachtelungstiefe fest, geklemmt von 1 bis 4096. |
  | `indent`                     | `string`  | No       | Legt die Einrückungszeichenfolge fest, begrenzt auf 32 Zeichen.        |

  ## Beispiel

  Encode JSON-compatible values mit derselben function wie json.encode.

  ```lua theme={null}
  local text = json.stringify({
      status = "ready",
      count = 3,
      tags = json.array({ "stringify", "alias" }),
      missing = json.null,
  }, {
      sortKeys = true,
  })

  print(text)
  ```
</div>
