Syntax error with JSON query result

11 views
Skip to first unread message

Yves

unread,
Aug 29, 2009, 8:28:18 PM8/29/09
to Open-Tran.eu
Hi Jacek,

I was trying out the new JSON interface, hopping it would be faster
than the RCP one, and I'm running into problems. For example, using
the following query:

http://en.fr.open-tran.eu/json/suggest/Thumb%20drive

It seems the JSON output send back has some syntax error according the
JSON parser I use (which seems to work fine with other projects so
far).
To try to verify I've checked the string at http://www.jsonlint.com/
and apparently it agrees there is a problem, giving: "syntax error,
unexpected TINVALID, expecting TSTRING or '}' at line 3".

Checking visually is a bit difficult since the response is quite long
(and it's hard to find a query that gives a short list back). It does
look fine to me, but I'm no JSON expert, and at least two JSON parsers
seem to not like it.

-ys


Jacek Śliwerski

unread,
Aug 30, 2009, 4:17:35 AM8/30/09
to open...@googlegroups.com
Yves pisze:
>
> http://en.fr.open-tran.eu/json/suggest/Thumb%20drive

>
> Checking visually is a bit difficult since the response is quite long
> (and it's hard to find a query that gives a short list back). It does
> look fine to me, but I'm no JSON expert, and at least two JSON parsers
> seem to not like it.

Your intuition was very good :) The output indeed looks good and would
be accepted by the browser's evaluation engine, because it constitutes a
valid JavaScript object. Unfortunately, I wasn't aware that the strings
in JSON must be double-quoted, not single-quoted. And my version of
Python on the server is too old to have the json module in the library.
So I implemented my own in a somewhat non-compliant way.

The implementation is correct now and validates in jsonlint.com.

Thank you for the feedback!
Jacek

Yves Savourel

unread,
Aug 30, 2009, 1:52:56 PM8/30/09
to open...@googlegroups.com
> Your intuition was very good :) The output indeed looks good and would
> be accepted by the browser's evaluation engine, because it constitutes a
> valid JavaScript object. Unfortunately, I wasn't aware that the strings
> in JSON must be double-quoted, not single-quoted. And my version of
> Python on the server is too old to have the json module in the library.
> So I implemented my own in a somewhat non-compliant way.
>
> The implementation is correct now and validates in jsonlint.com.
>
> Thank you for the feedback!
> Jacek

Great! Thanks for working on this so promptly.

I think there may be still a least one escaping problem, a side effect of the fix.
Try to parse the result of http://en.es.open-tran.eu/json/suggest/file

Somewhere there is:

"name": "GNOME",
"orig_phrase": "File exists \\"{0}\\".",
"path": "G/evolution"

And that cause problem with the parser. I think it should be:

"name": "GNOME",
"orig_phrase": "File exists \\\"{0}\\\".",
"path": "G/evolution"

Cheers,
-ys


Jacek Śliwerski

unread,
Aug 30, 2009, 4:23:25 PM8/30/09
to open...@googlegroups.com
Yves Savourel pisze:

>
> I think there may be still a least one escaping problem, a side effect of the fix.
> Try to parse the result of http://en.es.open-tran.eu/json/suggest/file
>
> Somewhere there is:
>
> "name": "GNOME",
> "orig_phrase": "File exists \\"{0}\\".",
> "path": "G/evolution"
>
> And that cause problem with the parser. I think it should be:
>
> "name": "GNOME",
> "orig_phrase": "File exists \\\"{0}\\\".",
> "path": "G/evolution"

Stupid me! I have already fixed it and verified that the strings are
fine now.

Good catch. Thanks!
Jacek

Yves Savourel

unread,
Aug 30, 2009, 11:55:41 PM8/30/09
to open...@googlegroups.com
Hi Jacek,

> ...I have already fixed it and verified that the strings are
> fine now.

Yes, it work fine now.
Thanks for fixing this so quickly.

Now if some day we could have the equivalent of suggest3() in REST it would be great :)

Cheers,
-ys

Reply all
Reply to author
Forward
0 new messages