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

> Parse un JSON string puis le re-encode en readable formatted JSON avec Real JSON parser et encoder.

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

  ## Arguments

  <ParamField path={"json"} type={"string"} required>
    JSON string a parse avant le formatting. L'function lit cet argument avec string type checking.
  </ParamField>

  <ParamField path={"encodeOptions"} type={"EncodeOptions"}>
    Optional encode options passees au re-encode step. json.format lit les memes encode options que json.encode, puis force pretty a true.
  </ParamField>

  <ParamField path={"decodeOptions"} type={"DecodeOptions"}>
    Optional decode options utilisees pendant le parsing de l'input JSON. Un boolean definit useNull. Une table peut definir useNull et maxDepth.
  </ParamField>

  ## Retours

  <ResponseField name={"formatted"} type={"string"}>
    Readable formatted JSON string produit apres parsing et re-encoding de l'input.
  </ResponseField>

  ## Types

  ### EncodeOptions

  Contrôle la sérialisation et le formatage JSON.

  | Name                         | Type      | Required | Description                                                              |
  | ---------------------------- | --------- | -------- | ------------------------------------------------------------------------ |
  | `pretty`                     | `boolean` | No       | Permet une sortie JSON formatée et multiligne.                           |
  | `sortKeys`                   | `boolean` | No       | Trie les clés d'objet avant l'encodage.                                  |
  | `emptyTableAsArray`          | `boolean` | No       | Encode une table vide sous forme de tableau au lieu d'un objet.          |
  | `errorOnUnsupported`         | `boolean` | No       | Génère une erreur au lieu de remplacer des valeurs non prises en charge. |
  | `encodeInvalidNumbersAsNull` | `boolean` | No       | Encode NaN et les nombres infinis en JSON null.                          |
  | `maxDepth`                   | `integer` | No       | Définit la profondeur d'imbrication maximale, comprise entre 1 et 4 096. |
  | `indent`                     | `string`  | No       | Définit la chaîne d'indentation, limitée à 32 caractères.                |

  ### DecodeOptions

  Contrôle le comportement d'analyse JSON.

  | Name       | Type      | Required | Description                                                                      |
  | ---------- | --------- | -------- | -------------------------------------------------------------------------------- |
  | `useNull`  | `boolean` | No       | Représente JSON null avec la sentinelle nulle de la bibliothèque au lieu de nil. |
  | `maxDepth` | `integer` | No       | Définit la profondeur d'imbrication maximale, comprise entre 1 et 4 096.         |

  ## Exemple

  Parse existing JSON puis re-encode en 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>
