JSON & forward slashes

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

JSON & forward slashes

Robert Carpenter
Hey there-

I'm parsing some JSON output from Vimeo.com, and I found a but of  
weirdness between Lasso's JSON decoder and vimeo's output of URLs or  
other content with forward slashes - or perhaps the problem is with  
the rather loose spec of JSON itself. If I'm reading the RFC right, it  
sounds like forward slashes *may* be, but are not required to be,  
escaped. Vimeo chooses to escape their slashes, JSON.lasso does not  
catch this out of the box.

Looks like I've been able to fix this on my install by editing the  
JSON.lasso file, specifically by adding  " & (Replace: '\\/', '/')"  
near the end of line 202 in the decode_json tag. Haven't done  
extensive testing yet, so it may all blow up in a big ball of flame,  
but seems to be working for now.

Hope that helps someone who runs into a similar issue.

-Robert-

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/


Reply | Threaded
Open this post in threaded view
|

Re: JSON & forward slashes

jasonhuck
Thanks for discovering this, Robert.

It's very common for developers to escape forward slashes in
JavaScript strings, so even if it's not a part of the official JSON
spec, my preference would be that the Lasso implementation allow for
it.

- jason




On Tue, Apr 7, 2009 at 8:53 PM, Robert Carpenter <[hidden email]> wrote:

> Hey there-
>
> I'm parsing some JSON output from Vimeo.com, and I found a but of weirdness
> between Lasso's JSON decoder and vimeo's output of URLs or other content
> with forward slashes - or perhaps the problem is with the rather loose spec
> of JSON itself. If I'm reading the RFC right, it sounds like forward slashes
> *may* be, but are not required to be, escaped. Vimeo chooses to escape their
> slashes, JSON.lasso does not catch this out of the box.
>
> Looks like I've been able to fix this on my install by editing the
> JSON.lasso file, specifically by adding  " & (Replace: '\\/', '/')" near the
> end of line 202 in the decode_json tag. Haven't done extensive testing yet,
> so it may all blow up in a big ball of flame, but seems to be working for
> now.
>
> Hope that helps someone who runs into a similar issue.
>
> -Robert-
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>
>
>



--
tagSwap.net :: Open Source Lasso Code
<http://tagSwap.net/>

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/


Reply | Threaded
Open this post in threaded view
|

Re: JSON & forward slashes

Steve Upton
At 11:09 PM -0400 4/7/09, Jason Huck wrote:
>Thanks for discovering this, Robert.
>
>It's very common for developers to escape forward slashes in
>JavaScript strings, so even if it's not a part of the official JSON
>spec, my preference would be that the Lasso implementation allow for
>it.

As JSON strings are all in quotes, why would encoding of anything but quotes be necessary?

It would seem the encoding of slashes is in fact an incorrect forming of JSON...

regards,

Steve Upton


--


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/


Reply | Threaded
Open this post in threaded view
|

Re: JSON & forward slashes

jasonhuck
I'm not sure why people do it, I just see it in the wild a lot. The
only reason I have ever done it personally is because otherwise the
forward slashes tend to throw off syntax coloring in some editors.
There may be more significant reasons. Also, in my experience, you can
usually escape any character you want, whether it's strictly
necessary/required or not. This is just one case where I think the
"decoder" should be a little more relaxed.

- jason






On Wed, Apr 8, 2009 at 2:29 PM, Steve Upton <[hidden email]> wrote:

> At 11:09 PM -0400 4/7/09, Jason Huck wrote:
>>Thanks for discovering this, Robert.
>>
>>It's very common for developers to escape forward slashes in
>>JavaScript strings, so even if it's not a part of the official JSON
>>spec, my preference would be that the Lasso implementation allow for
>>it.
>
> As JSON strings are all in quotes, why would encoding of anything but quotes be necessary?
>
> It would seem the encoding of slashes is in fact an incorrect forming of JSON...
>
> regards,
>
> Steve Upton
>
>
> --
>
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>
>
>



--
tagSwap.net :: Open Source Lasso Code
<http://tagSwap.net/>

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/


Reply | Threaded
Open this post in threaded view
|

Re: JSON & forward slashes

Robert Carpenter
In reply to this post by Steve Upton
I think it's a legacy of javascript's handling of control characters  
and special characters in strings - tabs, new lines, etc., plus ?, \,  
etc.

If you check out the spiffy railroad diagrams on json.org, you'll see  
that crockford provides a list of chars to escape, including the  
forward slash (incorrectly identified as a solidus, but no need to be  
pedantic here :-)

However, if you look at the RFC, it says:
" All Unicode characters may be placed within the
    quotation marks except for the characters that must be escaped:
    quotation mark, reverse solidus, and the control characters (U+0000
    through U+001F)."

Note that the forward slash is not among that set:

http://www.ssec.wisc.edu/~tomw/java/unicode.html#x0000

I don't think lasso is alone in figuring out how to reliably and  
"correctly" parse JSON - see my note to come in a few minutes...

-Robert-


On Apr 8, 2009, at 11:29 AM, Steve Upton wrote:

> At 11:09 PM -0400 4/7/09, Jason Huck wrote:
>> Thanks for discovering this, Robert.
>>
>> It's very common for developers to escape forward slashes in
>> JavaScript strings, so even if it's not a part of the official JSON
>> spec, my preference would be that the Lasso implementation allow for
>> it.
>
> As JSON strings are all in quotes, why would encoding of anything  
> but quotes be necessary?
>
> It would seem the encoding of slashes is in fact an incorrect  
> forming of JSON...
>
> regards,
>
> Steve Upton
>
>
> --
>
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>
>


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/