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

> 使用 Real JSON string escaping rules 对 string 执行 escape，并返回不带 surrounding quotes 的 escaped content。

<div className="real-function-page">
  ```lua theme={null}
  json.escape(text: string): string
  ```

  ## 参数

  <ParamField path={"text"} type={"string"} required>
    要 escape 的 string。function 使用 string type checking 读取这个 argument。
  </ParamField>

  ## 返回值

  <ResponseField name={"escaped"} type={"string"}>
    不带 opening 和 closing quote 的 escaped JSON string content。Quotes、backslashes、common control characters 和 bytes below 0x20 会被 escape。
  </ResponseField>

  ## 示例

  为 JSON string 内部 escape string，不添加 surrounding quotes。

  ```lua theme={null}
  local source = "line 1" .. string.char(10) .. [[line "2"]]
  local escaped = json.escape(source)

  print(escaped)
  ```
</div>
