Function: formatJson()
ts
function formatJson(value, indent?): string;Formats a JSON string or object with indentation. 将 JSON 字符串或对象格式化为带缩进的字符串。
Parameters
| Parameter | Type | Default value |
|---|---|---|
value | unknown | undefined |
indent | number | 2 |
Returns
string
Example
ts
formatJson({ a: 1 }) // => '{\n "a": 1\n}'
formatJson('{"a":1}') // => '{\n "a": 1\n}'Since
1.3.0