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: | ||
Status: | Closed | Last Modified: | 2013-07-04 17:25:23 | |
Resolution: | Not Applicable Here | Closed By: | ||
Closed on: | ||||
Description: |
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: |
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 |