> ## 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 ثم يعيد 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
  ```

  ## الوسائط

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

  ## القيم الراجعة

  <ResponseField name={"formatted"} type={"string"}>
    Readable formatted JSON string يتم انتاجه بعد parsing و re-encoding للـ input.
  </ResponseField>

  ## الأنواع

  ### 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 مع الحارس الفارغ للمكتبة بدلاً من صفر. |
  | `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>
