Example for json.pretty (#10466)
This commit is contained in:
parent
fa7b757823
commit
7118e1ca01
1 changed files with 22 additions and 3 deletions
|
|
@ -708,6 +708,25 @@ proc toPretty(result: var string, node: JsonNode, indent = 2, ml = true,
|
||||||
proc pretty*(node: JsonNode, indent = 2): string =
|
proc pretty*(node: JsonNode, indent = 2): string =
|
||||||
## Returns a JSON Representation of `node`, with indentation and
|
## Returns a JSON Representation of `node`, with indentation and
|
||||||
## on multiple lines.
|
## on multiple lines.
|
||||||
|
##
|
||||||
|
## Similar to prettyprint in Python.
|
||||||
|
##
|
||||||
|
## **Examples:**
|
||||||
|
##
|
||||||
|
## .. code-block:: Nim
|
||||||
|
## let j = %* {"name": "Isaac", "books": ["Robot Dreams"],
|
||||||
|
## "details": {"age":35, "pi":3.1415}}
|
||||||
|
## echo pretty(j)
|
||||||
|
## # {
|
||||||
|
## # "name": "Isaac",
|
||||||
|
## # "books": [
|
||||||
|
## # "Robot Dreams"
|
||||||
|
## # ],
|
||||||
|
## # "details": {
|
||||||
|
## # "age": 35,
|
||||||
|
## # "pi": 3.1415
|
||||||
|
## # }
|
||||||
|
## # }
|
||||||
result = ""
|
result = ""
|
||||||
toPretty(result, node, indent)
|
toPretty(result, node, indent)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue