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

JSON tcl parser error

114 views
Skip to first unread message

Luc Moulinier

unread,
Jul 1, 2016, 11:47:48 AM7/1/16
to
Hello !

I try to parse a JSON string receieved from a web server used quite a lot by the bioinformatics community (EBI web services).
Parsing the string using tcllib jason package failed, as well as the json-procs.tcl from OpenFACS. Both parsers give the same error message :

unexpected token "[" at position 2; expecting STRING
while executing
"unexpected $tokenCursor $token "STRING""
(procedure "parseObjectMember" line 26)

Is there a bug in JSON Tcl parser, or is it really a mal-formed JSON string ?
(As far as I can unserstand, it seems it doesn't like the first element to be a JSON array ...)

Many thanks for your help !!
Luc

The JSON text is :

{[{"model_length":"76","align":["#HMM tvaGrvtsisdrsggkvifidlrDgt.griqvvlfreeatklaenlkeGdvvrvtGrvkrr....pgg...elelkveeiell","#MATCH ++ G++ ++ +r g+++if lrD ++iq+v ++ +l++ ++ +dvv++ G ++ + + e+e++ e+i++l","#PP 579***********************6677887777....*********************66651.15779********986","#SEQ VLNGWIEQKPKRVGKNLIFGLLRDSNgDIIQLVDNK----SLLKGFTLEDVVQAVGILSLKrklsN-EdadEYEVQLEDITVL"],"env":{"to":"128","from":"50"},"name":"tRNA_anti-codon","acc":"PF01336.22","sig":1,"evalue":"1.6e-06","hmm":{"to":"76","from":"2"},"desc":"OB-fold nucleic acid binding domain","act_site":null,"type":"Domain","bits":"27.9","clan":"CL0021","seq":{"to":"128","from":"51","name":"SYDM_YEAST"}},{"model_length":"314","align":["#HMM knryldlrtekvsavlrlrstvtkavrkyleengfieietPiLvksdteegarlFkvksrekek....effaLtqspqlylellivagldrvfqiaraFRaEdsrtdrhlaEFtqieaemsfieeeeimqvleelikslvkevlessakeiefvirrns.....kdlkkpfkrltykeaieklneigkdldkaderalvk......................................................................................................................................keknepvfvtdfP............................aelkpFyakkeedd........kkltesyDllingvElvgGslRiedpeeleeklkskgldeeaeekfswylealeyGapphgGlglGldRlvmlllgsesIrdviaFPk","#MATCH ++ryl+lr++k+++ l+ rs++ k +r+ +++ +f+e+etP+L+k+ t+egar+F+v++r+k++ +f+aL qspq+y++ll+++g+++++q+ar+FR+Ed+r+dr++ EFtq+++em+f++ e++m+++e+ ++ +++++ +++++ ++ + + + ++ + ++ r+ty++a++ +++dk+d+ra +k + +++dfP ++++pF++ k +d+ k+l ++yDl++ngvEl+gGs+Ri+dp+++ ++++ + ++a e f+++l+a+++G+pph+G+++G+dR++++++++esIrdviaFPk","#PP 79********************************************.***************444567******************************************.********************************.6666888888777778887444444599**********.....**********98789**********************************************************************************************************************************999999**********************************************************************************************99999***********************************************9","#SEQ EFRYLQLRNPKYQDFLKKRSSISKEIRNSFNNFDFTEVETPMLFKA-TPEGAREFLVPTRTKRSdgkpSFYALDQSPQQYKQLLMASGVNKYYQMARCFRDEDLRADRQP-EFTQVDMEMAFANSEDVMKIIEKTVSGVWSKF-SKKRGLLTLDSKGTLvpakkENGTVSIFRMTYEQAMTS-----YGIDKPDLRAPDLkiinlgefnafshlnkkfpvfeviilrsafsnmeeykerwsfltnnsnynyrvpivlpiendeqansnwfenfhaiatfenphlitkflklkkgdivcgctrepnhsifenptplgrlrqlvlqsehgkniyhaVNKDVASWIVDFPlfspviiedksgkkeklaypeyekdrlcSTHHPFTMVKLKDYeklektpeKCLGRHYDLVVNGVELGGGSTRIHDPRLQDYIFEDILKIDNAYELFGHLLNAFDMGTPPHAGFAIGFDRMCAMICETESIRDVIAFPK"],"env":{"to":"628","from":"145"},"name":"tRNA-synt_2","acc":"PF00152.17","sig":1,"evalue":"4.7e-101","hmm":{"to":"312","from":"7"},"desc":"tRNA synthetases class II (D, K and N) ","act_site":null,"type":"Domain","bits":"337.8","clan":"CL0040","seq":{"to":"626","from":"150","name":"SYDM_YEAST"}}]}

Rich

unread,
Jul 1, 2016, 12:18:47 PM7/1/16
to
Luc Moulinier <luc.mo...@igbmc.fr> wrote:
> Hello !
>
> I try to parse a JSON string receieved from a web server used quite a
> lot by the bioinformatics community (EBI web services). Parsing the
> string using tcllib jason package failed, as well as the
> json-procs.tcl from OpenFACS. Both parsers give the same error
> message :
>
> unexpected token "[" at position 2; expecting STRING
> while executing
> "unexpected $tokenCursor $token "STRING""
> (procedure "parseObjectMember" line 26)
>
> Is there a bug in JSON Tcl parser, or is it really a mal-formed JSON string ?
>
> {[...]}

How did you download this string from the server (i.e., what's the
download code look like?).

I ask because it is common to get curly brackets around a string when
interpreting something that is a list as if it were a string:

$ rlwrap tclsh
% set list [list "hello goodbye"]
{hello goodbye}
% puts $list
{hello goodbye}
%

The curlies above are added by the Tcl list->string formatting
procedure when you try to display the list as if it were a string.

Is it possible you have a Tcl list, and you are not doing [lindex $list
0] to get the string content of the first (or whichever) element?

Rich

unread,
Jul 1, 2016, 12:23:09 PM7/1/16
to
Luc Moulinier <luc.mo...@igbmc.fr> wrote:
> Hello !
>
> I try to parse a JSON string receieved from a web server used quite a
> lot by the bioinformatics community (EBI web services). Parsing the
> string using tcllib jason package failed, as well as the
> json-procs.tcl from OpenFACS. Both parsers give the same error
> message :

Pasting your sample string here
https://jsonformatter.curiousconcept.com/ results in the same error but
a different message text. So this string is invalid.

Now you just need to figure out how it is becoming invalid.

Luc Moulinier

unread,
Jul 4, 2016, 7:52:32 AM7/4/16
to
Many thanks !
You analysis is right ! Getting the real string solves the problem !

Thanks again !
Luc
0 new messages