• possible dict bug?

    From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Wed Jan 14 10:49:11 2026
    From Newsgroup: comp.lang.tcl

    When I run the following program I get an unexpected error:

    #!/usr/bin/env tclsh9
    package require http 2
    package require json 1
    package require tls 2
    ::http::register https 443 ::tls::socket
    set t [http::geturl https://api.dictionaryapi.dev/api/v2/entries/en/repeat]
    if {[http::status $t] eq "ok"} {
    set d [json::json2dict [http::data $t]]
    puts "dict=«$d»"
    puts "keys=«[dict keys $d]»"
    }
    http::cleanup $t

    Output (most is elided):

    dict=«{word repeat phonetics {…} meanings {…} …}»
    missing value to go with key
    while executing
    "dict keys $d"
    invoked from within
    "if {[http::status $t] eq "ok"} {
    set d [json::json2dict [http::data $t]]
    puts "dict=«$d»"
    puts "keys=«[dict keys $d]»"
    }"
    (file "/tmp/bug.tcl" line 7)

    I tried copying and pasting the data (between the chevrons) into tkcon:

    % set d {word repeat phonetics {{...

    and then tried there:

    % dict keys $d
    word phonetics meanings license sourceUrls

    so it works inside tkcon but not in my own program.

    Am I making a mistake or is it really a bug?

    Using Tcl/Tk 9.0.3 on 64-bit Linux.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Rich@rich@example.invalid to comp.lang.tcl on Wed Jan 14 15:26:05 2026
    From Newsgroup: comp.lang.tcl

    Mark Summerfield <m.n.summerfield@gmail.com> wrote:
    When I run the following program I get an unexpected error:

    #!/usr/bin/env tclsh9
    package require http 2
    package require json 1
    package require tls 2
    ::http::register https 443 ::tls::socket
    set t [http::geturl https://api.dictionaryapi.dev/api/v2/entries/en/repeat] if {[http::status $t] eq "ok"} {
    set d [json::json2dict [http::data $t]]
    puts "dict=«$d»"
    puts "keys=«[dict keys $d]»"
    }
    http::cleanup $t

    Output (most is elided):

    dict=«{word repeat phonetics {…} meanings {…} …}»

    While you likely manually 'trimmed' the above, the value to which you
    trimmed it also generates the same error in Tcl 8:

    $ rlwrap tclsh
    % dict keys {word repeat phonetics {…} meanings {…} …}
    missing value to go with key

    The reason why is that there are an odd number of elements present.
    Dict reports "missing value to go with key" when there is an odd number
    of elements in the string it is trying to parse.

    Am I making a mistake or is it really a bug?

    I suspect something is broken in the string inside the $d var, but as
    the full string was omitted I can't say my suspision is accurate.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Wed Jan 14 18:32:36 2026
    From Newsgroup: comp.lang.tcl

    On Wed, 14 Jan 2026 15:26:05 -0000 (UTC), Rich wrote:

    Mark Summerfield <m.n.summerfield@gmail.com> wrote:
    When I run the following program I get an unexpected error:

    #!/usr/bin/env tclsh9
    package require http 2
    package require json 1
    package require tls 2
    ::http::register https 443 ::tls::socket
    set t [http::geturl https://api.dictionaryapi.dev/api/v2/entries/en/repeat] >> if {[http::status $t] eq "ok"} {
    set d [json::json2dict [http::data $t]]
    puts "dict=«$d»"
    puts "keys=«[dict keys $d]»"
    }
    http::cleanup $t

    Output (most is elided):

    dict=«{word repeat phonetics {…} meanings {…} …}»

    While you likely manually 'trimmed' the above, the value to which you trimmed it also generates the same error in Tcl 8:

    $ rlwrap tclsh
    % dict keys {word repeat phonetics {…} meanings {…} …}
    missing value to go with key

    The reason why is that there are an odd number of elements present.
    Dict reports "missing value to go with key" when there is an odd number
    of elements in the string it is trying to parse.

    Am I making a mistake or is it really a bug?

    I suspect something is broken in the string inside the $d var, but as
    the full string was omitted I can't say my suspision is accurate.

    The full string I get back is:

    {word repeat phonetics {{audio https://api.dictionaryapi.dev/media/pronunciations/en/repeat-uk.mp3 sourceUrl https://commons.wikimedia.org/w/index.php?curid=9028725 license {name {BY 3.0 US} url https://creativecommons.org/licenses/by/3.0/us}} {audio https://api.dictionaryapi.dev/media/pronunciations/en/repeat-us.mp3 sourceUrl https://commons.wikimedia.org/w/index.php?curid=1780322 license {name {BY-SA 3.0} url https://creativecommons.org/licenses/by-sa/3.0}}} meanings {{partOfSpeech noun definitions {{definition {An iteration; a repetition.} synonyms {} antonyms {} example {We gave up after the third repeat because it got boring.}} {definition {A television program shown after its initial presentation; a rerun.} synonyms {} antonyms {}} {definition {A refill of a prescription.} synonyms {} antonyms {}} {definition {A pattern of nucleic acids that occur in multiple copies throughout a genome (or of amino acids in a protein).} synonyms {} antonyms {}} {definition {A mark in music notation directing a part to be repeated.} synonyms {} antonyms {}}} synonyms {reiteration reoccurrence} antonyms {}} {partOfSpeech verb definitions {{definition {To do or say again (and again).} synonyms {} antonyms {} example {The scientists repeated the experiment in order to confirm the result.}} {definition {To refill (a prescription).} synonyms {} antonyms {}} {definition {To happen again; recur.} synonyms {} antonyms {}} {definition {To echo the words of (a person).} synonyms {} antonyms {}} {definition {To strike the hours, as a watch does.} synonyms {} antonyms {}} {definition {To make trial of again; to undergo or encounter again.} synonyms {} antonyms {}} {definition {To repay or refund (an excess received).} synonyms {} antonyms {}} {definition {(procedure word) To call in a previous artillery fire mission with the same ammunition and method either on the coordinates or adjusted either because destruction of the target was insufficient or missed.} synonyms {} antonyms {} example {Add 100, left 50. Repeat, over.}} {definition {To commit fraud in an election by voting more than once for the same candidate.} synonyms {} antonyms {}}} synonyms {redo reiterate reprise rework reoccur} antonyms {}}} license {name {CC BY-SA 3.0} url https://creativecommons.org/licenses/by-sa/3.0} sourceUrls https://en.wiktionary.org/wiki/repeat}

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From et99@et99@rocketship1.me to comp.lang.tcl on Wed Jan 14 11:37:20 2026
    From Newsgroup: comp.lang.tcl

    On 1/14/2026 10:32 AM, Mark Summerfield wrote:
    On Wed, 14 Jan 2026 15:26:05 -0000 (UTC), Rich wrote:

    Mark Summerfield <m.n.summerfield@gmail.com> wrote:
    When I run the following program I get an unexpected error:

    #!/usr/bin/env tclsh9
    package require http 2
    package require json 1
    package require tls 2
    ::http::register https 443 ::tls::socket
    set t [http::geturl https://api.dictionaryapi.dev/api/v2/entries/en/repeat] >>> if {[http::status $t] eq "ok"} {
    set d [json::json2dict [http::data $t]]
    puts "dict=«$d»"
    puts "keys=«[dict keys $d]»"
    }
    http::cleanup $t

    Output (most is elided):

    dict=«{word repeat phonetics {…} meanings {…} …}»

    While you likely manually 'trimmed' the above, the value to which you
    trimmed it also generates the same error in Tcl 8:

    $ rlwrap tclsh
    % dict keys {word repeat phonetics {…} meanings {…} …}
    missing value to go with key

    The reason why is that there are an odd number of elements present.
    Dict reports "missing value to go with key" when there is an odd number
    of elements in the string it is trying to parse.

    Am I making a mistake or is it really a bug?

    I suspect something is broken in the string inside the $d var, but as
    the full string was omitted I can't say my suspision is accurate.

    The full string I get back is:

    {word repeat phonetics {{audio https://api.dictionaryapi.dev/media/pronunciations/en/repeat-uk.mp3 sourceUrl https://commons.wikimedia.org/w/index.php?curid=9028725 license {name {BY 3.0 US} url https://creativecommons.org/licenses/by/3.0/us}} {audio https://api.dictionaryapi.dev/media/pronunciations/en/repeat-us.mp3 sourceUrl https://commons.wikimedia.org/w/index.php?curid=1780322 license {name {BY-SA 3.0} url https://creativecommons.org/licenses/by-sa/3.0}}} meanings {{partOfSpeech noun definitions {{definition {An iteration; a repetition.} synonyms {} antonyms {} example {We gave up after the third repeat because it got boring.}} {definition {A television program shown after its initial presentation; a rerun.} synonyms {} antonyms {}} {definition {A refill of a prescription.} synonyms {} antonyms {}} {definition {A pattern of nucleic acids that occur in multiple copies throughout a genome (or of amino acids in a protein).} synonyms {} antonyms {}} {definition {A mark in music notation directing a part to be repeated.} synonyms {} antonyms {}}} synonyms {reiteration reoccurrence} antonyms {}} {partOfSpeech verb definitions {{definition {To do or say again (and again).} synonyms {} antonyms {} example {The scientists repeated the experiment in order to confirm the result.}} {definition {To refill (a prescription).} synonyms {} antonyms {}} {definition {To happen again; recur.} synonyms {} antonyms {}} {definition {To echo the words of (a person).} synonyms {} antonyms {}} {definition {To strike the hours, as a watch does.} synonyms {} antonyms {}} {definition {To make trial of again; to undergo or encounter again.} synonyms {} antonyms {}} {definition {To repay or refund (an excess received).} synonyms {} antonyms {}} {definition {(procedure word) To call in a previous artillery fire mission with the same ammunition and method either on the coordinates or adjusted either because destruction of the target was insufficient or missed.} synonyms {} antonyms {} example {Add 100, left 50. Repeat, over.}} {definition {To commit fraud in an election by voting more than once for the same candidate.} synonyms {} antonyms {}}} synonyms {redo reiterate reprise rework reoccur} antonyms {}}} license {name {CC BY-SA 3.0} url https://creativecommons.org/licenses/by-sa/3.0} sourceUrls https://en.wiktionary.org/wiki/repeat}


    try it with:

    puts "keys=«[dict keys [lindex $d 0]]»"

    Otherwise $d is a list of 1 item

    -e



    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Rich@rich@example.invalid to comp.lang.tcl on Wed Jan 14 23:02:28 2026
    From Newsgroup: comp.lang.tcl

    Mark Summerfield <m.n.summerfield@gmail.com> wrote:
    On Wed, 14 Jan 2026 15:26:05 -0000 (UTC), Rich wrote:

    Mark Summerfield <m.n.summerfield@gmail.com> wrote:
    When I run the following program I get an unexpected error:

    #!/usr/bin/env tclsh9
    package require http 2
    package require json 1
    package require tls 2
    ::http::register https 443 ::tls::socket
    set t [http::geturl https://api.dictionaryapi.dev/api/v2/entries/en/repeat] >>> if {[http::status $t] eq "ok"} {
    set d [json::json2dict [http::data $t]]
    puts "dict=«$d»"
    puts "keys=«[dict keys $d]»"
    }
    http::cleanup $t

    Output (most is elided):

    dict=«{word repeat phonetics {…} meanings {…} …}»

    While you likely manually 'trimmed' the above, the value to which you
    trimmed it also generates the same error in Tcl 8:

    $ rlwrap tclsh
    % dict keys {word repeat phonetics {…} meanings {…} …}
    missing value to go with key

    The reason why is that there are an odd number of elements present.
    Dict reports "missing value to go with key" when there is an odd number
    of elements in the string it is trying to parse.

    Am I making a mistake or is it really a bug?

    I suspect something is broken in the string inside the $d var, but as
    the full string was omitted I can't say my suspision is accurate.

    The full string I get back is:

    {word repeat phonetics {{audio https://api.dictionaryapi.dev/media/pronunciations/en/repeat-uk.mp3 sourceUrl https://commons.wikimedia.org/w/index.php?curid=9028725 license {name {BY 3.0 US} url https://creativecommons.org/licenses/by/3.0/us}} {audio https://api.dictionaryapi.dev/media/pronunciations/en/repeat-us.mp3 sourceUrl https://commons.wikimedia.org/w/index.php?curid=1780322 license {name {BY-SA 3.0} url https://creativecommons.org/licenses/by-sa/3.0}}} meanings {{partOfSpeech noun definitions {{definition {An iteration; a repetition.} synonyms {} antonyms {} example {We gave up after the third repeat because it got boring.}} {definition {A television program shown after its initial presentation; a rerun.} synonyms {} antonyms {}} {definition {A refill of a prescription.} synonyms {} antonyms {}} {definition {A pattern of nucleic acids that occur in multiple copies throughout a genome (or of amino acids in a protein).} synonyms {} antonyms {}} {definition {A mark in music notation directing a part to be repeated.} synonyms {} antonyms {}}} synonyms {reiteration reoccurrence} antonyms {}} {partOfSpeech verb definitions {{definition {To do or say again (and again).} synonyms {} antonyms {} example {The scientists repeated the experiment in order to confirm the result.}} {definition {To refill (a prescription).} synonyms {} antonyms {}} {definition {To happen again; recur.} synonyms {} antonyms {}} {definition {To echo the words of (a person).} synonyms {} antonyms {}} {definition {To strike the hours, as a watch does.} synonyms {} antonyms {}} {definition {To make trial of again; to undergo or encounter again.} synonyms {} antonyms {}} {definition {To repay or refund (an excess received).} synonyms {} antonyms {}} {definition {(procedure word) To call in a previous artillery fire mission with the same ammunition and method either on the coordinates or adjusted either because destruction of the target was insufficient or missed.} synonyms {} antonyms {} example {Add 100, left 50. Repeat, over.}} {definition {To commit fraud in an election by voting more than once for the same candidate.} synonyms {} antonyms {}}} synonyms {redo reiterate reprise rework reoccur} antonyms {}}} license {name {CC BY-SA 3.0} url https://creativecommons.org/licenses/by-sa/3.0} sourceUrls https://en.wiktionary.org/wiki/repeat}

    With 8.6 I get:

    % dict keys $q
    word phonetics meanings license sourceUrls
    %

    So you may have found some weird bug.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From et99@et99@rocketship1.me to comp.lang.tcl on Wed Jan 14 20:54:54 2026
    From Newsgroup: comp.lang.tcl

    On 1/14/2026 3:02 PM, Rich wrote:
    Mark Summerfield <m.n.summerfield@gmail.com> wrote:
    On Wed, 14 Jan 2026 15:26:05 -0000 (UTC), Rich wrote:

    Mark Summerfield <m.n.summerfield@gmail.com> wrote:
    When I run the following program I get an unexpected error:

    #!/usr/bin/env tclsh9
    package require http 2
    package require json 1
    package require tls 2
    ::http::register https 443 ::tls::socket
    set t [http::geturl https://api.dictionaryapi.dev/api/v2/entries/en/repeat]
    if {[http::status $t] eq "ok"} {
    set d [json::json2dict [http::data $t]]
    puts "dict=«$d»"
    puts "keys=«[dict keys $d]»"
    }
    http::cleanup $t

    Output (most is elided):

    dict=«{word repeat phonetics {…} meanings {…} …}»

    While you likely manually 'trimmed' the above, the value to which you
    trimmed it also generates the same error in Tcl 8:

    $ rlwrap tclsh
    % dict keys {word repeat phonetics {…} meanings {…} …}
    missing value to go with key

    The reason why is that there are an odd number of elements present.
    Dict reports "missing value to go with key" when there is an odd number
    of elements in the string it is trying to parse.

    Am I making a mistake or is it really a bug?

    I suspect something is broken in the string inside the $d var, but as
    the full string was omitted I can't say my suspision is accurate.

    The full string I get back is:

    {word repeat phonetics {{audio https://api.dictionaryapi.dev/media/pronunciations/en/repeat-uk.mp3 sourceUrl https://commons.wikimedia.org/w/index.php?curid=9028725 license {name {BY 3.0 US} url https://creativecommons.org/licenses/by/3.0/us}} {audio https://api.dictionaryapi.dev/media/pronunciations/en/repeat-us.mp3 sourceUrl https://commons.wikimedia.org/w/index.php?curid=1780322 license {name {BY-SA 3.0} url https://creativecommons.org/licenses/by-sa/3.0}}} meanings {{partOfSpeech noun definitions {{definition {An iteration; a repetition.} synonyms {} antonyms {} example {We gave up after the third repeat because it got boring.}} {definition {A television program shown after its initial presentation; a rerun.} synonyms {} antonyms {}} {definition {A refill of a prescription.} synonyms {} antonyms {}} {definition {A pattern of nucleic acids that occur in multiple copies throughout a genome (or of amino acids in a protein).} synonyms {} antonyms {}} {definition {A mark in music notation directing a part to be repeated.} synonyms {} antonyms {}}} synonyms {reiteration reoccurrence} antonyms {}} {partOfSpeech verb definitions {{definition {To do or say again (and again).} synonyms {} antonyms {} example {The scientists repeated the experiment in order to confirm the result.}} {definition {To refill (a prescription).} synonyms {} antonyms {}} {definition {To happen again; recur.} synonyms {} antonyms {}} {definition {To echo the words of (a person).} synonyms {} antonyms {}} {definition {To strike the hours, as a watch does.} synonyms {} antonyms {}} {definition {To make trial of again; to undergo or encounter again.} synonyms {} antonyms {}} {definition {To repay or refund (an excess received).} synonyms {} antonyms {}} {definition {(procedure word) To call in a previous artillery fire mission with the same ammunition and method either on the coordinates or adjusted either because destruction of the target was insufficient or missed.} synonyms {} antonyms {} example {Add 100, left 50. Repeat, over.}} {definition {To commit fraud in an election by voting more than once for the same candidate.} synonyms {} antonyms {}}} synonyms {redo reiterate reprise rework reoccur} antonyms {}}} license {name {CC BY-SA 3.0} url https://creativecommons.org/licenses/by-sa/3.0} sourceUrls https://en.wiktionary.org/wiki/repeat}

    With 8.6 I get:

    % dict keys $q
    word phonetics meanings license sourceUrls
    %

    So you may have found some weird bug.

    Rich, what is $q ?

    The reason he is getting the error is that the json text is an array of a single (complex) object.

    Notice (if you go to the url and click on raw json) it begins [{"word":"repeat","phonetics":[{"audio":...

    What tkcon has done with the typed in command that the OP partially shows:

    % set d {word repeat phonetics {{...

    is to treat that as a single word containing a list/dict like text string, and thus removes the outer {}'s.

    And that is why it works there, but not when he does,

    set d [json::json2dict [http::data $t]]

    which sends the full json text to json2dict, which created a list of 1 element for the top level json array.

    -e


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Rich@rich@example.invalid to comp.lang.tcl on Thu Jan 15 05:10:50 2026
    From Newsgroup: comp.lang.tcl

    et99 <et99@rocketship1.me> wrote:
    On 1/14/2026 3:02 PM, Rich wrote:
    Mark Summerfield <m.n.summerfield@gmail.com> wrote:
    On Wed, 14 Jan 2026 15:26:05 -0000 (UTC), Rich wrote:

    Mark Summerfield <m.n.summerfield@gmail.com> wrote:
    When I run the following program I get an unexpected error:

    #!/usr/bin/env tclsh9
    package require http 2
    package require json 1
    package require tls 2
    ::http::register https 443 ::tls::socket
    set t [http::geturl https://api.dictionaryapi.dev/api/v2/entries/en/repeat]
    if {[http::status $t] eq "ok"} {
    set d [json::json2dict [http::data $t]]
    puts "dict=«$d»"
    puts "keys=«[dict keys $d]»"
    }
    http::cleanup $t

    Output (most is elided):

    dict=«{word repeat phonetics {…} meanings {…} …}»

    While you likely manually 'trimmed' the above, the value to which you
    trimmed it also generates the same error in Tcl 8:

    $ rlwrap tclsh
    % dict keys {word repeat phonetics {…} meanings {…} …}
    missing value to go with key

    The reason why is that there are an odd number of elements present.
    Dict reports "missing value to go with key" when there is an odd number >>>> of elements in the string it is trying to parse.

    Am I making a mistake or is it really a bug?

    I suspect something is broken in the string inside the $d var, but as
    the full string was omitted I can't say my suspision is accurate.

    The full string I get back is:

    {word repeat phonetics {{audio https://api.dictionaryapi.dev/media/pronunciations/en/repeat-uk.mp3 sourceUrl https://commons.wikimedia.org/w/index.php?curid=9028725 license {name {BY 3.0 US} url https://creativecommons.org/licenses/by/3.0/us}} {audio https://api.dictionaryapi.dev/media/pronunciations/en/repeat-us.mp3 sourceUrl https://commons.wikimedia.org/w/index.php?curid=1780322 license {name {BY-SA 3.0} url https://creativecommons.org/licenses/by-sa/3.0}}} meanings {{partOfSpeech noun definitions {{definition {An iteration; a repetition.} synonyms {} antonyms {} example {We gave up after the third repeat because it got boring.}} {definition {A television program shown after its initial presentation; a rerun.} synonyms {} antonyms {}} {definition {A refill of a prescription.} synonyms {} antonyms {}} {definition {A pattern of nucleic acids that occur in multiple copies throughout a genome (or of amino acids in a protein).} synonyms {} antonyms {}} {definition {A mark in music notation directing a part to be repeated.} synonyms {} antonyms {}}} synonyms {reiteration reoccurrence} antonyms {}} {partOfSpeech verb definitions {{definition {To do or say again (and again).} synonyms {} antonyms {} example {The scientists repeated the experiment in order to confirm the result.}} {definition {To refill (a prescription).} synonyms {} antonyms {}} {definition {To happen again; recur.} synonyms {} antonyms {}} {definition {To echo the words of (a person).} synonyms {} antonyms {}} {definition {To strike the hours, as a watch does.} synonyms {} antonyms {}} {definition {To make trial of again; to undergo or encounter again.} synonyms {} antonyms {}} {definition {To repay or refund (an excess received).} synonyms {} antonyms {}} {definition {(procedure word) To call in a previous artillery fire mission with the same ammunition and method either on the coordinates or adjusted either because destruction of the target was insufficient or missed.} synonyms {} antonyms {} example {Add 100, left 50. Repeat, over.}} {definition {To commit fraud in an election by voting more than once for the same candidate.} synonyms {} antonyms {}}} synonyms {redo reiterate reprise rework reoccur} antonyms {}}} license {name {CC BY-SA 3.0} url https://creativecommons.org/licenses/by-sa/3.0} sourceUrls https://en.wiktionary.org/wiki/repeat}

    With 8.6 I get:

    % dict keys $q
    word phonetics meanings license sourceUrls
    %

    So you may have found some weird bug.

    Rich, what is $q ?

    The contents of the "string" that mark posted here. I.e the item two
    lines below the text "The full string I get back is:"

    The reason he is getting the error is that the json text is an array
    of a single (complex) object.

    Notice (if you go to the url and click on raw json) it begins [{"word":"repeat","phonetics":[{"audio":...

    What tkcon has done with the typed in command that the OP partially
    shows:

    % set d {word repeat phonetics {{...

    is to treat that as a single word containing a list/dict like text
    string, and thus removes the outer {}'s.

    And that is why it works there, but not when he does,

    set d [json::json2dict [http::data $t]]

    which sends the full json text to json2dict, which created a list of
    1 element for the top level json array.

    Ah, yes, that would make all the difference.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Christian Gollwitzer@auriocus@gmx.de to comp.lang.tcl on Thu Jan 15 08:16:42 2026
    From Newsgroup: comp.lang.tcl

    Am 15.01.26 um 06:10 schrieb Rich:
    et99 <et99@rocketship1.me> wrote:
    And that is why it works there, but not when he does,

    set d [json::json2dict [http::data $t]]

    which sends the full json text to json2dict, which created a list of
    1 element for the top level json array.

    Ah, yes, that would make all the difference.

    One noteworthy point is that the name json2dict is misleading. Yes it
    makes dicts from json objects, but lists from json arrays, and
    rightfully so - OTOH in Tcl you can't distinguish between lists and
    dicts because of EIAS, therefore the type information from the json is
    lost. You need to know externally how the json is structured. If you
    need to access the type, you can use tdom or rl_json.

    Christian

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From et99@et99@rocketship1.me to comp.lang.tcl on Wed Jan 14 23:40:06 2026
    From Newsgroup: comp.lang.tcl

    On 1/14/2026 11:16 PM, Christian Gollwitzer wrote:
    Am 15.01.26 um 06:10 schrieb Rich:
    et99 <et99@rocketship1.me> wrote:
    And that is why it works there, but not when he does,

        set d [json::json2dict [http::data $t]]

    which sends the full json text to json2dict, which created a list of
    1 element for the top level json array.

    Ah, yes, that would make all the difference.

    One noteworthy point is that the name json2dict is misleading. Yes it makes dicts from json objects, but lists from json arrays, and rightfully so - OTOH in Tcl you can't distinguish between lists and dicts because of EIAS, therefore the type information from the json is lost. You need to know externally how the json is structured. If you need to access the type, you can use tdom or rl_json.

               Christian


    Yes, arrays are a particular problem, the tcl json package doesn't preserve type info.

    There was a discussion last year on exactly this which led me to experiment with a pure-tcl json parser that supports tdom-like type info. It's useful as long as you don't need to parse huge texts; for that Rolf's Tdom is the gold standard.

    It can be found here:

    https://github.com/rocketship88/typed-json-tcl

    also

    https://wiki.tcl-lang.org/page/typed%2Djson

    -e

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Thu Jan 15 12:32:06 2026
    From Newsgroup: comp.lang.tcl

    [snip]
    try it with:

    puts "keys=«[dict keys [lindex $d 0]]»"

    Otherwise $d is a list of 1 item

    -e

    Thanks to you and the others for explaining & giving good suggestions.
    --- Synchronet 3.21a-Linux NewsLink 1.2