From: tom.rmadilo on
On Mar 9, 5:17 pm, Bezoar <cwjo...(a)gmail.com> wrote:
> I am trying to parse a json reply from a web server so I naturally
> used the tcllib json package. My first order of business was to see
> what keys were needed to access the data I wanted. I wrote a proc to
> recurse into the dict and it fails. The first problem I encountered is
> that an json array is converted to a list so for instance for the
> following json snippet which represents a javascript array:
>
> ..."link":["rel","alternate","type","text html","href"],...
>
> is converted to this dict snippet
>
> .... link { rel alternate type {text html} href } ....
>
> there is no way to tell the resulting dict to not interpet list as a
> dict. You have to know this before hand. So if your input changes so
> does your code. Since javascript would access the results of the as
> link[0] == "rel"  why not auto index when converting to dict. I
> changed my json2dict function to do that so now for the example above
> the following results.

I wrote a json parser which creates a Tcl list which can be converted
back to a json structure:

http://junom.com/json/

Code is in the .tcl~ files, or you can try out the conversion with the
web form.

The code has no helper functions to look up data, or anything to
create a json structure, but it does create a Tcl encoding which
distinguishes the different structural elements to any depth.

The main difference between json and tcl structures is that both
arrays and lists are anonymous in json, not sure if a dict actually
matches up with a json structure.