Menu

#317 json2dict improvements index json arrays in dict

open
json (1)
5
2010-03-10
2010-03-10
C Jolly
No

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" } ....

Discussion

  • C Jolly

    C Jolly - 2010-03-10

    Modified json 1.0 (numbered 1.1)

     
  • C Jolly

    C Jolly - 2010-03-10

    Driver code for changes

     
  • C Jolly

    C Jolly - 2010-03-10

    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.

     
  • C Jolly

    C Jolly - 2010-03-10

    Modified tcllib 1.12 json.tcl version

     
  • C Jolly

    C Jolly - 2010-03-10

    Driver script with new call semantics

     
  • Andreas Kupries

    Andreas Kupries - 2010-03-10
    • labels: 705578 --> json
    • assigned_to: andreas_kupries --> hobbs
     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.