I modified the json 1.0 package with code (attached) that adds a option switch to add an index to json arrays when converted to dict format and all values remain quoted. See example below. After looking in the tracker I see that json.tcl has changed dramatically but I still want the new features. see attached driver code also
Input json snippet :
..."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 is key,value or a list. You would 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 accept the -indexlists option to do just that so now for the example above the following results.
.... link { 0 rel 1 alternate 2 type 3 {text html} 4 href } ....
Thats pretty good but then the next problem cropped up notice the { text html } ? Is it text or
another dict ( i.e key value } ? If you did not know what to expect (and you won't) this is bad news. I changed the json2dict script to maintain the quotes about the values and now the json above is converted to:
.... link { 0 "rel" 1 "alternate" 2 "type" 3 {"text html"} 4 "href" } ....
Modified json 1.0 (numbered 1.1)
Driver code for changes
Looked at the new code and modified it to work like what I had done with the 1.0 version with some minor changes. The value quoting is optional and rather than using args to json2dict I use defaults
so instead of "json2dict jsontxt -indexlists 1 " you have "json2dict jsontxt true true " where first true is for indexlists and 2nd true is for quotevalues. I also attach the modified driver script.
Modified tcllib 1.12 json.tcl version
Driver script with new call semantics