Tcl Library Source Code

View Ticket
Bounty program for improvements to Tcl and certain Tcl packages.
Ticket UUID: 2967134
Title: json2dict improvements index json arrays in dict
Type: RFE Version: None
Submitter: cwjolly Created on: 2010-03-10 03:04:44
Subsystem: json Assigned To: hobbs
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2016-04-28 07:42:14
Resolution: None Closed By: nobody
    Closed on:
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" } ....
User Comments: anonymous (claiming to be heinrichmartin) added on 2016-04-28 07:42:14:
Please don't break the representation of lists and dicts. Although the idea of breaks the EIAS principle and makes use of [::tcl::unsupported], the suggested change would break that working code.

It looks like you want to default to legacy behavior, so my comment might be void. It is just to give another view on the topic.

anonymous added on 2013-07-02 22:46:52:
The quoting around all values is unnecessary; it is sufficient to simply require that a value (string, number or bareword) is parsed as a list of length 1.

cwjolly added on 2010-03-10 10:39:18:
File Added - 366074: jsondriver2.tcl

cwjolly added on 2010-03-10 10:38:29:
File Added - 366073: json.tcl

cwjolly added on 2010-03-10 10:37:46:
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.

cwjolly added on 2010-03-10 10:06:05:
File Added - 366072: jsondriver.tcl

cwjolly added on 2010-03-10 10:04:49:
File Added - 366071: json.tcl