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 {…} …}»
Am I making a mistake or is it really a bug?
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.
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}
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}
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.
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.
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.
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
try it with:
puts "keys=«[dict keys [lindex $d 0]]»"
Otherwise $d is a list of 1 item
-e
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,096 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 366:05:45 |
| Calls: | 14,034 |
| Calls today: | 2 |
| Files: | 187,081 |
| D/L today: |
1,733 files (529M bytes) |
| Messages: | 2,478,509 |