aboutsummaryrefslogtreecommitdiff
path: root/jim_tcl.txt
diff options
context:
space:
mode:
authordbohdan <dbohdan@dbohdan.com>2019-11-09 19:54:10 +0000
committerdbohdan <dbohdan@dbohdan.com>2019-11-11 05:00:23 +0000
commitea69c35ddd6842bca86711e504968236b70cf426 (patch)
treeb610be02f6d893d6c10fe712a944165338b02b00 /jim_tcl.txt
parent7bb4dffaa22b9d90982a561f464d54a7f20c2032 (diff)
downloadjimtcl-ea69c35ddd6842bca86711e504968236b70cf426.zip
jimtcl-ea69c35ddd6842bca86711e504968236b70cf426.tar.gz
jimtcl-ea69c35ddd6842bca86711e504968236b70cf426.tar.bz2
json: implement -index decode option
Diffstat (limited to 'jim_tcl.txt')
-rw-r--r--jim_tcl.txt10
1 files changed, 7 insertions, 3 deletions
diff --git a/jim_tcl.txt b/jim_tcl.txt
index 2ad1f25..01c33b4 100644
--- a/jim_tcl.txt
+++ b/jim_tcl.txt
@@ -5371,10 +5371,12 @@ json::decode
The JSON -> Tcl decoder is part of the optional 'json' package.
-+*json::decode* ?*-null* 'string'? ?*-schema*? 'json-string'+::
++*json::decode* ?*-index*? ?*-null* 'string'? ?*-schema*? 'json-string'+::
-Decodes the given JSON string (must be array or object) into a Tcl data structure. If '+-schema+' is specified, returns a
-list of +'{data schema}'+ where the schema is compatible with `json::encode`. Otherwise just returns the data.
+Decodes the given JSON string (must be array or object) into a Tcl data structure. If '+-index+' is specified,
+decodes JSON arrays as dictionaries with numeric keys. This makes it possible to retrieve data from nested
+arrays and dictionaries with just '+dict get+'. With the option '+-schema+' returns a list of +'{data schema}'+
+where the schema is compatible with `json::encode`. Otherwise just returns the data.
Decoding is as follows (with schema types listed in parentheses):
* object -> dict ('obj')
* array -> list ('mixed' or 'list')
@@ -5393,6 +5395,8 @@ Decoding is as follows (with schema types listed in parentheses):
{a 1 b 2} {obj a num b num}
. json::decode -schema {[1, 2, {a:"b", c:false}, "hello"]}
{1 2 {a b c false} hello} {mixed num num {obj a str c bool} str}
+ . json::decode -index {["foo", "bar"]}
+ {0 foo 1 bar}
----
[[BuiltinVariables]]