> ## 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 JSON string แล้ว re-encode เป็น readable formatted JSON ด้วย Real JSON parser และ 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 ที่ถูก parse ก่อน formatting. function อ่าน argument นี้ด้วย string type checking.
  </ParamField>

  <ParamField path={"encodeOptions"} type={"EncodeOptions"}>
    Optional encode options ที่ส่งเข้า re-encode step. json.format อ่าน encode options เดียวกับ json.encode แล้วบังคับ pretty เป็น true.
  </ParamField>

  <ParamField path={"decodeOptions"} type={"DecodeOptions"}>
    Optional decode options ที่ใช้ระหว่าง parsing input JSON. boolean ตั้งค่า useNull. table ตั้งค่า useNull และ maxDepth ได้.
  </ParamField>

  ## Returns

  <ResponseField name={"formatted"} type={"string"}>
    Readable formatted JSON string ที่สร้างหลัง parsing และ re-encoding input.
  </ResponseField>

  ## Types

  ### EncodeOptions

  ควบคุมการทำให้เป็นอนุกรมและการจัดรูปแบบ JSON

  | Name | Type | Required | คำอธิบาย |
  | - | - | - | - |
  | `pretty` | `boolean` | No | เปิดใช้งานเอาต์พุต JSON แบบหลายบรรทัดที่จัดรูปแบบแล้ว |
  | `sortKeys` | `boolean` | No | เรียงลำดับออบเจ็กต์คีย์ก่อนการเข้ารหัส |
  | `emptyTableAsArray` | `boolean` | No | เข้ารหัสตารางว่างเป็นอาร์เรย์แทนที่จะเป็นวัตถุ |
  | `errorOnUnsupported` | `boolean` | No | ทำให้เกิดข้อผิดพลาดแทนที่จะแทนที่ค่าที่ไม่รองรับ |
  | `encodeInvalidNumbersAsNull` | `boolean` | No | เข้ารหัส NaN และจำนวนอนันต์เป็น JSON null |
  | `maxDepth` | `integer` | No | ตั้งค่าความลึกของการซ้อนสูงสุด โดยยึดไว้ตั้งแต่ 1 ถึง 4096 |
  | `indent` | `string` | No | ตั้งค่าสตริงการเยื้อง โดยจำกัดไว้ที่ 32 อักขระ |

  ### DecodeOptions

  ควบคุมพฤติกรรมการแยกวิเคราะห์ JSON

  | Name | Type | Required | คำอธิบาย |
  | - | - | - | - |
  | `useNull` | `boolean` | No | แสดงถึง JSON null ด้วย null sentinel ของไลบรารีแทนที่จะเป็น nil |
  | `maxDepth` | `integer` | No | ตั้งค่าความลึกของการซ้อนสูงสุด โดยยึดไว้ตั้งแต่ 1 ถึง 4096 |

  ## ตัวอย่าง

  Parse existing JSON แล้ว re-encode เป็น 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>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.