The existing json2dict is painfully slow -- perhaps, because it is implemented
in pure Tcl. Needing to parse large (20-60Mb) JSON files I wrote my own... First
as simply a wrapper around the json-c library:
This implementation uses json-c for actual parsing (which creates a tree of
json-c's own objects) and then lazily translates chunks of that tree into proper
Tcl_Objects. This is about 15 times faster than json2dict found in tcllib can do.
But it requires a 3rd-party library and uses additional memory (and time) -- for
that library's own object-tree, which then needs to be translated... So I
implemented my own parser from scratch -- using the grammar posted on json.org
Here is my tcljson.y (requires a modern yacc or bison -- no lex). Maybe, some
day it will become part of tcllib, but in the mean time you are welcome to test
it and/or use it. Made available under BSD-license:
With this, my own scripts become even faster than their equivalents written in
PHP (where JSON-parsing is native).