Skip to content

Function: formatJson() ​

ts
function formatJson(value, indent?): string;

Formats a JSON string or object with indentation. 将 JSON 字符串或对象格式化为带缩进的字符串。

Parameters ​

ParameterTypeDefault value
valueunknownundefined
indentnumber2

Returns ​

string

Example ​

ts
formatJson({ a: 1 }) // => '{\n  "a": 1\n}'
formatJson('{"a":1}') // => '{\n  "a": 1\n}'

Since ​

1.3.0

Released under the MIT License.