> ## 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.format

> Parsed einen JSON string und encoded ihn mit Real JSON parser und encoder wieder als readable formatted JSON.

<div className="real-function-page">
  ```lua theme={null}
  json.format(json: string, encodeOptions?: EncodeOptions, decodeOptions?: DecodeOptions): string
  ```

  ## Argumente

  <ParamField path={"json"} type={"string"} required>
    JSON string, der vor dem formatting parsed wird. Die function liest dieses argument mit string type checking.
  </ParamField>

  <ParamField path={"encodeOptions"} type={"EncodeOptions"}>
    Optional encode options fuer den re-encode step. json.format liest dieselben encode options wie json.encode und setzt danach pretty auf true.
  </ParamField>

  <ParamField path={"decodeOptions"} type={"DecodeOptions"}>
    Optional decode options fuer das parsing des input JSON. Ein boolean setzt useNull. Eine table kann useNull und maxDepth setzen.
  </ParamField>

  ## Rückgaben

  <ResponseField name={"formatted"} type={"string"}>
    Readable formatted JSON string, der nach parsing und re-encoding des input erzeugt wird.
  </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.        |

  ### DecodeOptions

  Steuert das JSON-Parsing-Verhalten.

  | Name       | Type      | Required | Beschreibung                                                                 |
  | ---------- | --------- | -------- | ---------------------------------------------------------------------------- |
  | `useNull`  | `boolean` | No       | Stellt JSON Null mit dem Null-Sentinel der Bibliothek anstelle von Null dar. |
  | `maxDepth` | `integer` | No       | Legt die maximale Verschachtelungstiefe fest, geklemmt von 1 bis 4096.       |

  ## Beispiel

  Parse existing JSON und re-encode es als readable formatted JSON.

  ```lua theme={null}
  local compact = '{"b":2,"a":1}'
  local formatted = json.format(compact, {
      pretty = true,
      sortKeys = true,
  }, {
      useNull = true,
  })

  print(formatted)
  ```
</div>
