You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by Massimo Manghi <ma...@unipr.it> on 2020/12/01 11:21:31 UTC

json parser in yajltcl

I've been extensively using FA's yajltcl package lately to compose JSON 
messages to be consumed and interpreted by a browser internal parser

I also ran into the need of parsing JSON messages myself and from what I 
understood yajltcl converts JSON back to the original yajltcl sequence 
that created it but offers no way to organize the data into some Tcl 
native container, is it correct? A parser that converts the yajltcl 
representation of the JSON data in some Tcl native representation is 
something needed to yajltcl?

  -- Massimo


---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: json parser in yajltcl

Posted by Jeff L <je...@bovine.net>.
json2dict is mentioned in the quick reference section of the README.md file
in the repo:
https://github.com/flightaware/yajl-tcl

There's no particular technical reason why you can't parse/manipulate the
command format sequence, but it's just not as convenient to do because of
the nature of the data. However, if your needs are simple, you can use the
list functions like lsearch, linsert, lreplace, lrange to directly modify
that command format too.



On Wed, Dec 2, 2020 at 2:14 AM Massimo Manghi <ma...@unipr.it>
wrote:

> On 12/1/20 10:29 PM, Jeff L wrote:
> > yajltcl offers the ::yajl::json2dict for conversion of JSON messages
> > into a Tcl native container (which can be used as a dict or array). This
> > is the easiest way to read specific values from within a larger JSON
> > document since you can use normal dict/array operations to navigate the
> > data structure layout.
> >
>
> thank you. I based my knowledge on the documentation available from
> https://flightaware.github.io/yajl-tcl/ where I found the 'parse'
> command but not json2dict
>
> > The yajltcl command format (array_open/array_close/etc) is not really
> > intended to be consumed or manipulated by anything else directly, though
> > it's possible if your needs are simple enough.
> >
> >
>
> why not? Provided such sequences are a complete mapping of a JSON
> message DOM you should be able to build the actual inverse map.
>
>   -- M
>

Re: json parser in yajltcl

Posted by Massimo Manghi <ma...@unipr.it>.
On 12/1/20 10:29 PM, Jeff L wrote:
> yajltcl offers the ::yajl::json2dict for conversion of JSON messages 
> into a Tcl native container (which can be used as a dict or array). This 
> is the easiest way to read specific values from within a larger JSON 
> document since you can use normal dict/array operations to navigate the 
> data structure layout.
> 

thank you. I based my knowledge on the documentation available from 
https://flightaware.github.io/yajl-tcl/ where I found the 'parse' 
command but not json2dict

> The yajltcl command format (array_open/array_close/etc) is not really 
> intended to be consumed or manipulated by anything else directly, though 
> it's possible if your needs are simple enough.
> 
> 

why not? Provided such sequences are a complete mapping of a JSON 
message DOM you should be able to build the actual inverse map.

  -- M

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: json parser in yajltcl

Posted by Jeff L <je...@bovine.net>.
yajltcl offers the ::yajl::json2dict for conversion of JSON messages into a
Tcl native container (which can be used as a dict or array). This is the
easiest way to read specific values from within a larger JSON document
since you can use normal dict/array operations to navigate the data
structure layout.

The yajltcl command format (array_open/array_close/etc) is not really
intended to be consumed or manipulated by anything else directly, though
it's possible if your needs are simple enough.



On Tue, Dec 1, 2020 at 5:22 AM Massimo Manghi <ma...@unipr.it>
wrote:

> I've been extensively using FA's yajltcl package lately to compose JSON
> messages to be consumed and interpreted by a browser internal parser
>
> I also ran into the need of parsing JSON messages myself and from what I
> understood yajltcl converts JSON back to the original yajltcl sequence
> that created it but offers no way to organize the data into some Tcl
> native container, is it correct? A parser that converts the yajltcl
> representation of the JSON data in some Tcl native representation is
> something needed to yajltcl?
>
>   -- Massimo
>
>

Re: json parser in yajltcl

Posted by Massimo Manghi <ma...@unipr.it>.

On 12/1/20 1:38 PM, Harald Oehlmann wrote:
> Am 01.12.2020 um 12:21 schrieb Massimo Manghi:
>> I've been extensively using FA's yajltcl package lately to compose 
>> JSON messages to be consumed and interpreted by a browser internal parser
>>
>> I also ran into the need of parsing JSON messages myself and from what 
>> I understood yajltcl converts JSON back to the original yajltcl 
>> sequence that created it but offers no way to organize the data into 
>> some Tcl native container, is it correct? A parser that converts the 
>> yajltcl representation of the JSON data in some Tcl native 
>> representation is something needed to yajltcl?
> 
> Dear Massimo,
> 
> thank you for the message. I suppose, this would be good work.
> May I point your attention to tdom which is now able to parse and 
> construct JSON in a similar manner as XML. In addition, you get the 
> additional fruit, that you may choose the output format the last moment 
> (JSON or XML).
> 
> I have not tried this but it might be a strategic thought.
> 
> Thank you,
> Harald
> 


Thank you Harald,

I had tdom at work for years in most of my Rivet projects and I became 
accustomed to the fact that it was pretty stable but had little 
development, event though a version 1.0.0 is still due. I missed the 
JSON support. I ought to follow more closely the release of new stuff......

nonetheless I fiddled around with yajltcl and wrote a simple Tcl parser 
of the yajltcl dom representation. For the test cases I could figure out 
the parser produces a Tcl dictionary. The pitfall of a dictionary is 
that in order to read the data correctly you need to know beforehand 
what is the dom structure stored in the dictionary, but this is often 
the case when exchanging specific application messages. I guess that 
creating a struct::tree representation to remove ambiguities would be 
straightforward


  -- Massimo

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: json parser in yajltcl

Posted by Harald Oehlmann <ha...@elmicron.de>.
Am 01.12.2020 um 12:21 schrieb Massimo Manghi:
> I've been extensively using FA's yajltcl package lately to compose JSON 
> messages to be consumed and interpreted by a browser internal parser
> 
> I also ran into the need of parsing JSON messages myself and from what I 
> understood yajltcl converts JSON back to the original yajltcl sequence 
> that created it but offers no way to organize the data into some Tcl 
> native container, is it correct? A parser that converts the yajltcl 
> representation of the JSON data in some Tcl native representation is 
> something needed to yajltcl?

Dear Massimo,

thank you for the message. I suppose, this would be good work.
May I point your attention to tdom which is now able to parse and 
construct JSON in a similar manner as XML. In addition, you get the 
additional fruit, that you may choose the output format the last moment 
(JSON or XML).

I have not tried this but it might be a strategic thought.

Thank you,
Harald

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org