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

> Parsuje JSON string i ponownie encode'uje go jako readable formatted JSON przy uzyciu Real JSON parser i encoder.

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

  ## Argumenty

  <ParamField path={"json"} type={"string"} required>
    JSON string parsowany przed formatting. Function czyta ten argument przez string type checking.
  </ParamField>

  <ParamField path={"encodeOptions"} type={"EncodeOptions"}>
    Optional encode options przekazywane do re-encode step. json.format czyta te same encode options co json.encode, a potem wymusza pretty na true.
  </ParamField>

  <ParamField path={"decodeOptions"} type={"DecodeOptions"}>
    Optional decode options uzywane podczas parsing input JSON. boolean ustawia useNull. table moze ustawic useNull i maxDepth.
  </ParamField>

  ## Zwroty

  <ResponseField name={"formatted"} type={"string"}>
    Readable formatted JSON string utworzony po parsing i re-encoding input.
  </ResponseField>

  ## Typy

  ### EncodeOptions

  Kontroluje serializację i formatowanie JSON.

  | Name                         | Type      | Required | Opis                                                                            |
  | ---------------------------- | --------- | -------- | ------------------------------------------------------------------------------- |
  | `pretty`                     | `boolean` | No       | Włącza sformatowane, wielowierszowe wyjście JSON.                               |
  | `sortKeys`                   | `boolean` | No       | Sortuje klucze obiektów przed kodowaniem.                                       |
  | `emptyTableAsArray`          | `boolean` | No       | Koduje pustą tabelę jako tablicę zamiast obiektu.                               |
  | `errorOnUnsupported`         | `boolean` | No       | Zgłasza błąd zamiast zastępować nieobsługiwane wartości.                        |
  | `encodeInvalidNumbersAsNull` | `boolean` | No       | Koduje liczby NaN i nieskończone jako JSON null.                                |
  | `maxDepth`                   | `integer` | No       | Ustawia maksymalną głębokość zagnieżdżenia, zaciśniętą w zakresie od 1 do 4096. |
  | `indent`                     | `string`  | No       | Ustawia ciąg wcięcia ograniczony do 32 znaków.                                  |

  ### DecodeOptions

  Kontroluje zachowanie analizy JSON.

  | Name       | Type      | Required | Opis                                                                            |
  | ---------- | --------- | -------- | ------------------------------------------------------------------------------- |
  | `useNull`  | `boolean` | No       | Reprezentuje JSON null ze wskaźnikiem null biblioteki zamiast nil.              |
  | `maxDepth` | `integer` | No       | Ustawia maksymalną głębokość zagnieżdżenia, zaciśniętą w zakresie od 1 do 4096. |

  ## Przykład

  Parse existing JSON i re-encode jako 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>
