ztcl::json pretty
Lays out a JSON text with one member on each line.
ztcl::json pretty ?-indent N? TEXT
Description
Gives TEXT with one member or element on each line, N spaces for each level, and : after each key. An empty object stays {}. TEXT must be valid JSON.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| TEXT | JSON text | required | The text. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
-indent | integer | 2 | The count of spaces for each level. |
-indent N
The count of spaces for each level.
Each level of nesting gets N more spaces.
% ztcl::json pretty -indent 4 {{"a":1}}
{
"a": 1
}% ztcl::json pretty -indent x {{}}
expected an integer but got "x"
-errorcode ZT JSON OPTIONReturns
The JSON text.
Examples
Each example of this page runs after package require ztcl::json.
% ztcl::json pretty {{"a":[1,2],"b":{}}}
{
"a": [
1,
2
],
"b": {}
}
Errors
% ztcl::json pretty {[1,}
json syntax error at line 1, column 4: value expected
-errorcode ZT JSON SYNTAX 1 4
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1