Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tcl dictionaries to/from [JSON or MySQL]

220 views
Skip to first unread message

Richard Owlett

unread,
Jul 24, 2018, 6:06:30 AM7/24/18
to
I've been using tcltutor30b7 on and off and have solved a few problems
with it's aid. I now know just enough to be dangerous while getting an
idea of what Tcl can do.

I have separate applications each using JSON or MySQL. I've neither the
time nor inclination to study either. I've browsed the Tcl wiki and
found a cornucopia of tools.

My applications are:
1. imposing organization on my SeaMonkey bookmarks in JSON format.
2. using cherrytree {http://www.giuspen.com/cherrytree/} a
hierarchical note taking application which uses MySQL. I will
be organizing some emails which are in a large ASCII file. I'll
have no problem parsing that file.

Suggestions/comments?
TIA

Jim

unread,
Jul 24, 2018, 2:34:23 PM7/24/18
to
On 7/24/2018 3:06 AM, Richard Owlett wrote:
> I now know just enough to be dangerous
> I've neither the time nor inclination to study

>>>
Suggestions/comments?

Have you tried to resolve the issues of time and inclination?

Is there something in particular about the applications that you
mentioned that you want suggestions or comments on? If you elaborate
you may get advice, suggestions or comments regarding them and tcl.

Richard Owlett

unread,
Jul 24, 2018, 4:01:00 PM7/24/18
to
As to time, I see three score and ten through a looking glass.
As to inclination, I already have motivation to enhance my meager /
Tcl/Tk skills. Although I once emitted 8085 assembler for hire, I refuse
to claim to be a programmer. Basically I'm looking for a translator. I
already have an idea of what Tcl dicts, lists, arrays, ... wish to
accomplish. IOW, if visiting a foreign country, would you hire a
competent translator or spend years gaining fluency in a foreign
language for a one time use.

See initial post. Interpret literally ;/
*ROFL* ;)
TIA






sled...@gmail.com

unread,
Jul 24, 2018, 7:23:00 PM7/24/18
to
Depends on the level of self-sufficiency requisite to meeting the objective - and, maybe, how much I am paying the translator.

heinrichmartin

unread,
Jul 25, 2018, 4:40:51 AM7/25/18
to
On Tuesday, July 24, 2018 at 12:06:30 PM UTC+2, Richard Owlett wrote:
> I've been using tcltutor30b7 on and off and have solved a few problems
> with it's aid. I now know just enough to be dangerous while getting an
> idea of what Tcl can do.
>
> I have separate applications each using JSON or MySQL. I've neither the
> time nor inclination to study either. I've browsed the Tcl wiki and
> found a cornucopia of tools.

Not seeing a question there, but trying to help ...

> My applications are:
> 1. imposing organization on my SeaMonkey bookmarks in JSON format.

Looks like you need not generate arbitrary JSON.
1. while parsing, also keep the original string and use it as needed
2. when modifying bookmarks is needed, you probably can educate the guesses made in https://rosettacode.org/wiki/JSON#Tcl. Personally, I use a procedure that takes not only the data as input, but also a translation table (i.e. which property is of which type).

Take the comment about "deep *UNSUPPORTED* magic!" serious! E.g. you cannot distinguish empty string, object, and array - and using the wrong one can bite you when sending the data to an API.

Richard Owlett

unread,
Jul 25, 2018, 7:35:17 AM7/25/18
to
Its example clarified a lot of things. I suspect my problem with the Tcl
wiki was it went into such detail that I didn't see the forest for the
trees. Extracting the data from the JSON is the critical portion of my
task. If I can't export the edited data back to JSON, I'll have in a
form I can manipulate. Likely I'll be able to create a HTML document
structure to be acceptable for cherrytree's HTML import function. If so
I'll not need to investigate Tcl<-->MySQL routines.

Thank you.


ifind...@gmail.com

unread,
Jul 29, 2018, 6:08:23 PM7/29/18
to
You may like this enhanced interface to the Tcl JSON package:

https://sourceforge.net/projects/tclfltk/files/Linux/jsondict/

Or maybe not. I use it for json->dict->edit->newdict->json all the time, but you know what happens when you let others use your software....

Richard Owlett

unread,
Jul 29, 2018, 8:52:04 PM7/29/18
to
I'll try to download it in the morning.
Attempting to use sourceforge if not fully awake is ... ;/
Thanks


Gerhard Reithofer

unread,
Aug 1, 2018, 5:08:06 PM8/1/18
to
Hi,
On Sun, 29 Jul 2018, Richard Owlett wrote:
> On 07/29/2018 05:08 PM, ifind...@gmail.com wrote:
> > On Tuesday, July 24, 2018 at 6:06:30 AM UTC-4, Richard Owlett wrote:

...

> > You may like this enhanced interface to the Tcl JSON package:
> > https://sourceforge.net/projects/tclfltk/files/Linux/jsondict/

The debian package seems to be broken, there is no file in the archive.

$ dpkg --listfiles jsondict
tells that the package does not contain a file :-(

Bye,
Gerhard

--
Gerhard Reithofer - Techn. EDV Reithofer - http://www.tech-edv.co.at

Richard Owlett

unread,
Aug 2, 2018, 2:01:16 PM8/2/18
to
On 08/01/2018 03:35 PM, Gerhard Reithofer wrote:
> Hi,
> On Sun, 29 Jul 2018, Richard Owlett wrote:
>> On 07/29/2018 05:08 PM, ifind...@gmail.com wrote:
>>> On Tuesday, July 24, 2018 at 6:06:30 AM UTC-4, Richard Owlett wrote:
>
> ...
>
>>> You may like this enhanced interface to the Tcl JSON package:
>>> https://sourceforge.net/projects/tclfltk/files/Linux/jsondict/
>
> The debian package seems to be broken, there is no file in the archive.
>
> $ dpkg --listfiles jsondict
> tells that the package does not contain a file :-(
>
> Bye,
> Gerhard
>
>

And I thought it was I was too asleep to press the right buttons ;/


ifind...@gmail.com

unread,
Aug 6, 2018, 12:59:08 PM8/6/18
to
On Tuesday, July 24, 2018 at 6:06:30 AM UTC-4, Richard Owlett wrote:
My apologies. I should check this stuff before any announcements. I have put up versions that look correct. I don't think its relevant as to which Tcl buid is used, but just in case...

Thanks for letting me know of any issues.

Richard Owlett

unread,
Aug 11, 2018, 10:20:05 AM8/11/18
to
On 07/24/2018 05:06 AM, Richard Owlett wrote:
> I've been using tcltutor30b7 on and off and have solved a few problems
> with it's aid. I now know just enough to be dangerous while getting an
> idea of what Tcl can do.
>

I've changed the immediate focus of my project.
My input data is a JSON file from SeaMonkey's bookmark backup routine.
I want to get into a form that Tcl can manipulate.
I tried:
> package require json
> set fileid [open "/home/richard/Documents/cherrytree/edit-bookmarks/minimal-08-11.json" RDONLY]
> seek $fileid 0 start
> set buffer [read $fileid];
> set line [::json::many-json2dict $buffer 4];
> puts $line
> close $fileid
>

Which gives error messages:> % Bad limit 4 of json entities to extract,
found only 1.
> % can't read "line": no such variable

Do I have a syntax error?
Is the JSON malformed?

A couple of weeks ago I was referred to
https://sourceforge.net/projects/tclfltk/files/Linux/jsondict/

I've read the included man page without great comprehension.
Are there actual usage examples?

TIA

Ted Nolan <tednolan>

unread,
Aug 11, 2018, 1:18:04 PM8/11/18
to
In article <Y46dnTbeMuYTbfPG...@supernews.com>,
Have you looked at rl_json ?

https://github.com/RubyLane/rl_json

It's very good at getting JSON into Tcl (and outputting it for that matter).
--
------
columbiaclosings.com
What's not in Columbia anymore..

Richard Owlett

unread,
Aug 11, 2018, 2:30:14 PM8/11/18
to
No. Never heard of it ;}

>
> https://github.com/RubyLane/rl_json

Downloaded it. Un-zipped it.
Documentation:
Forrest concealed by focus on leaves of tree ;[
Not new user friendly. Looks like what an "expert"would like.

Guess I'll have to use BASIC.
p.s. I predate Dartmouth BASIC. Used CORC/CUPL <we beat them in football
and hockey IIRC ;/

keithv

unread,
Aug 11, 2018, 3:03:23 PM8/11/18
to
: Guess I'll have to use BASIC.
: p.s. I predate Dartmouth BASIC. Used CORC/CUPL <we beat them in football
: and hockey IIRC ;/

Very interesting. But don't forget that Dartmouth and Basic also had DTSS, the first successful large-scale time-sharing system. So student programs could be developed interactively and didn't need to batch processed.

As to football, I leave you with two links:

o https://www.wikiwand.com/en/Cornell%E2%80%93Dartmouth_football_rivalry

o Also, the famous "The Fifth Down" https://www.wikiwand.com/en/Fifth_Down_Game_(1940)

Keith

Richard Owlett

unread,
Aug 11, 2018, 4:28:00 PM8/11/18
to
On 08/11/2018 02:03 PM, keithv wrote:
> : Guess I'll have to use BASIC.
> : p.s. I predate Dartmouth BASIC. Used CORC/CUPL <we beat them in football
> : and hockey IIRC ;/
>
> Very interesting. But don't forget that Dartmouth and Basic also had DTSS, the first successful large-scale time-sharing system. So student programs could be developed interactively and didn't need to batch processed.
>
> As to football, I leave you with two links:
>
> o https://www.wikiwand.com/en/Cornell%E2%80%93Dartmouth_football_rivalry

For the years I was on campus. I evidently was correct - would have to
did out transcript to verify.
When my father was on campus, no doubt.
You didn't mention hockey ;> In my day, we always made the ECAC playoffs.

BTW
Proof someone's sense of humor resembles mine.
They may even be as old as I.

>
> o Also, the famous "The Fifth Down" https://www.wikiwand.com/en/Fifth_Down_Game_(1940)

OK. You taught me something. I had always assumed Edmund and Ezra were
contemporaries. Their statues are less than ~50 fee3t apart ;}

P.S. In 1940 not only did I not exist, but my parents had not met.
>
> Keith
>

A side issue is confronting today's youngsters with concepts enunciated
by Turing in early 20th century. [Rest of paragraph intentionally *NOT*
written. ;]

BTW any flowchart I produce will have strong .relationship to BASIC.
Any code I produce will likely be in Tcl as it is more convenient.

/end of editorial <GRIN>

ifind...@gmail.com

unread,
Aug 12, 2018, 9:45:15 AM8/12/18
to
On Tuesday, July 24, 2018 at 6:06:30 AM UTC-4, Richard Owlett wrote:
Of course, you have already decoded the raw bookmark file using something like dejsonlz4 into a JSON file format. Using an example decoded file named backup.json, I fund this works:

package require jsondict
set fd [open backup.json r]
set json [read $fd]
close $fd
set dict [NewDict $json]

foreach { key value } $dict {
if { [llength $value] == 1 } {
puts "$key : $value"
} else {
puts "$key"
foreach {name data } $value {
puts "\t$name : $value"
}
}

Of course, you may wish to implement something a bit more refined to handle
the cases of sub-keys within the values, as they can go to more than 1 level.





Richard Owlett

unread,
Aug 12, 2018, 10:00:17 AM8/12/18
to
On 08/12/2018 08:45 AM, ifind...@gmail.com wrote:
> On Tuesday, July 24, 2018 at 6:06:30 AM UTC-4, Richard Owlett wrote:
>> I've been using tcltutor30b7 on and off and have solved a few problems
>> with it's aid. I now know just enough to be dangerous while getting an
>> idea of what Tcl can do.
>>
>> I have separate applications each using JSON or MySQL. I've neither the
>> time nor inclination to study either. I've browsed the Tcl wiki and
>> found a cornucopia of tools.
>>
>> My applications are:
>> 1. imposing organization on my SeaMonkey bookmarks in JSON format.
>> 2. using cherrytree {http://www.giuspen.com/cherrytree/} a
>> hierarchical note taking application which uses MySQL. I will
>> be organizing some emails which are in a large ASCII file. I'll
>> have no problem parsing that file.
>>
>> Suggestions/comments?
>> TIA
>
> Of course, you have already decoded the raw bookmark file using something like dejsonlz4 into a JSON file format. Using an example decoded file named backup.json, I fund this works:

I'm on SeaMonkey. Internally used bookmarks may be in that format.
However it can emit and accept JSON files.

>
> package require jsondict
> set fd [open backup.json r]
> set json [read $fd]
> close $fd
> set dict [NewDict $json]
>
> foreach { key value } $dict {
> if { [llength $value] == 1 } {
> puts "$key : $value"
> } else {
> puts "$key"
> foreach {name data } $value {
> puts "\t$name : $value"
> }
> }
>

I'll try it this afternoon. I'm on my way out the door now.

> Of course, you may wish to implement something a bit more refined to handle
> the cases of sub-keys within the values, as they can go to more than 1 level.

I suspect I'll be able to do brute force recursion by storing some
$value in temp file(s).

Thanks


heinrichmartin

unread,
Aug 13, 2018, 3:59:46 AM8/13/18
to
On Sunday, August 12, 2018 at 3:45:15 PM UTC+2, ifind...@gmail.com wrote:
> package require jsondict

Haven't found this one, neither through web search nor on http://wiki.tcl.tk/13419.

> set dict [NewDict $json]

Does this package really pollute the global namespace? Otherwise your example might lack a [namespace import ...].

Richard Owlett

unread,
Aug 13, 2018, 6:42:57 AM8/13/18
to
On 08/13/2018 02:59 AM, heinrichmartin wrote:
> On Sunday, August 12, 2018 at 3:45:15 PM UTC+2, ifind...@gmail.com wrote:
>> package require jsondict
>
> Haven't found this one, neither through web search nor on http://wiki.tcl.tk/13419.

I assume he is referring to
[https://sourceforge.net/projects/tclfltk/files/Linux/jsondict/]

I've downloaded jsondict-1.0.11-2-noarch-8.6.0.deb from there.
BUT I've forgotten how to install a package not in a repository.

ifind...@gmail.com

unread,
Aug 13, 2018, 7:47:53 AM8/13/18
to
On Tuesday, July 24, 2018 at 6:06:30 AM UTC-4, Richard Owlett wrote:
> Well, I assume you are using Linux of a Debian variety.

sudo dpkg -i path/to/downloads/jsondict-1.0.11-2....deb

at a command line should do it. Or, right click on the file in a directory listing and select gdebi as the target, or open the file with the archive manager and extract the package to where you want it and then set the TCLLIBPATH variable to point there, or use unzip on the file and then move the package files to where you want and set the TCLLIBPATH variable, or just set links in /usr/lib to the package directory (where extracted, of course) and do nothing, or extract the package directory into you application directory, or for this package just get the jsondict-1.0.tcl file and source it directly into your application and forget about the rest.....

Hope one of these methods works for you. If not, I consult at $100/hour plus travel expenses...

ifind...@gmail.com

unread,
Aug 13, 2018, 8:05:47 AM8/13/18
to
On Tuesday, July 24, 2018 at 6:06:30 AM UTC-4, Richard Owlett wrote:
Heinrich,
Indeed, I am a polluter of the global name space. Pure laziness. But only for a few utility functions. The bulk of the package is appended to the ::web:: space. Sorry, but I am not a true disciple and wrote this and other packages for my own use and entertainment. I am a climate change denier as well (according to some). All my stuff that I have released is on sourceforge in the tclfltk project.

Richard Owlett

unread,
Aug 13, 2018, 9:07:00 AM8/13/18
to
On 08/12/2018 09:00 AM, Richard Owlett wrote:
> On 08/12/2018 08:45 AM, ifind...@gmail.com wrote:
>> [snip]
>>
>> Of course, you have already decoded the raw bookmark file using
>> something like dejsonlz4 into a JSON file format. Using an example
>> decoded file named backup.json, I fund this works:
>
> I'm on SeaMonkey. Internally used bookmarks may be in that format.
> However it can emit and accept JSON files.
>
>>
>> package require jsondict
>> set fd [open backup.json r]
>> set json [read $fd]
>> close $fd
>> set dict [NewDict $json]
>>
>> foreach { key value } $dict {
>> if { [llength $value] == 1 } {
>> puts "$key : $value"
>> } else {
>> puts "$key"
>> foreach {name data } $value {
>> puts "\t$name : $value"
>> }
>> }
>>
>
> I'll try it this afternoon. I'm on my way out the door now.
>
>> Of course, you may wish to implement something a bit more refined to
>> handle
>> the cases of sub-keys within the values, as they can go to more than 1
>> level.

I had problems recalling that "dpkg -i" was the appropriate tool to
install jsondict-1.0.11-2-noarch-8.6.0.deb .

You demo script apparently hung in a infinite loop.
I discovered a missing "}" and added at the end.
It still hung.
I cannot assert my JSON file is well formed.
More later.

ifind...@gmail.com

unread,
Aug 13, 2018, 11:50:13 AM8/13/18
to
On Tuesday, July 24, 2018 at 6:06:30 AM UTC-4, Richard Owlett wrote:
Okay, I have all kinds of scripts for checking JSON file formats. You can mail me a copy of the file in question and I can apply my checkers if you want. I am fairly confident my jsondict package works on well formed JSON, but, I have learned that you find all kinds of disastrous bugs the minute you publish code. Maybe you have found one in my stuff....

Richard Owlett

unread,
Aug 15, 2018, 8:16:02 AM8/15/18
to
On 08/13/2018 10:50 AM, ifind...@gmail.com wrote:
> On Tuesday, July 24, 2018 at 6:06:30 AM UTC-4, Richard Owlett wrote:
>> I've been using tcltutor30b7 on and off and have solved a few problems
>> with it's aid. I now know just enough to be dangerous while getting an
^^^^^^^^^^^^^^^^^^^^^^^^^^^ <groan>
>> idea of what Tcl can do.
>>[snip]
>
> Okay, I have all kinds of scripts for checking JSON file formats. You can mail me a copy of the file in question and I can apply my checkers if you want. I am fairly confident my jsondict package works on well formed JSON, but, I have learned that you find all kinds of disastrous bugs the minute you publish code. Maybe you have found one in my stuff....
>

Seems I have two problems:
1. not understanding "MATE terminal" in Debian Stretch.
I had done a "copy-n-paste" into a terminal window.
The apparent "infinite loop" seems to have been a terminal issue.
I say apparent as I can not reproduce the symptom I repeatedly saw.
2. not understanding the script.
Student has homework assignment ;}

Thank you.



0 new messages