diff options
author | Mandeep Singh <reach.mandeep.singh@gmail.com> | 2019-01-30 10:35:45 -0500 |
---|---|---|
committer | Miran <narimiran@disroot.org> | 2019-01-30 16:35:45 +0100 |
commit | 7118e1ca01e1892208836411b3e4801f06b028c3 (patch) | |
tree | d8a0491989d3ea68c844ad17526b667d5e8b9c16 | |
parent | fa7b75782361fb31e74117a7e84ebe8fcda922c0 (diff) | |
download | Nim-7118e1ca01e1892208836411b3e4801f06b028c3.tar.gz |
Example for json.pretty (#10466)
-rw-r--r-- | lib/pure/json.nim | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim index ffb8f4f35..4a3d5b432 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -130,9 +130,9 @@ ## { "name": "Susan", "age": herAge } ## ] ## -## var j2 = %* {"name": "Isaac", "books": ["Robot Dreams"]} -## j2["details"] = %* {"age":35, "pi":3.1415} -## echo j2 +## var j2 = %* {"name": "Isaac", "books": ["Robot Dreams"]} +## j2["details"] = %* {"age":35, "pi":3.1415} +## echo j2 runnableExamples: ## Note: for JObject, key ordering is preserved, unlike in some languages, @@ -708,6 +708,25 @@ proc toPretty(result: var string, node: JsonNode, indent = 2, ml = true, proc pretty*(node: JsonNode, indent = 2): string = ## Returns a JSON Representation of `node`, with indentation and ## 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 = "" toPretty(result, node, indent) |