json parser patch

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

json parser patch

sebastianconcept@gmail.co
Maybe this is useful to someone:

Try this:

JSJsonParser parseStream: '{lhs: "1 Brazil real",rhs: "0.592768 U.S. dollars",error: "",icc: true}' readStream

it can't parse that, so..

...patch it with this:

JSJsonParser#parseProperty
| name value |
name := self parsePropertyName.
value := self parseValue.
^ self createProperty: name with: value.

JSJsonParser#parsePropertyName
| result |
result := WriteStream on: String new.
[ stream atEnd or: [ stream peek = $: ] ] 
whileFalse: [ result nextPut: self parseCharacter ].
^ self expect: ':'; createString: result contents

then you get it working like this:
 a Dictionary('error'->'' 'icc'->true 'lhs'->'1 Brazil real' 'rhs'->'0.592768 U.S. dollars' )


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: json parser patch

Lukas Renggli
The problem is that what you parse is not valid JSON, check the standard on json.org.

Lukas

On Monday, 12 September 2011, Sebastian Sastre <[hidden email]> wrote:
> Maybe this is useful to someone:
> Try this:
> JSJsonParser parseStream: '{lhs: "1 Brazil real",rhs: "0.592768 U.S. dollars",error: "",icc: true}' readStream
> it can't parse that, so..
> ...patch it with this:
> JSJsonParser#parseProperty
> | name value |
> name := self parsePropertyName.
> value := self parseValue.
> ^ self createProperty: name with: value.
> JSJsonParser#parsePropertyName
> | result |
> result := WriteStream on: String new.
> [ stream atEnd or: [ stream peek = $: ] ] 
> whileFalse: [ result nextPut: self parseCharacter ].
> ^ self expect: ':'; createString: result contents
> then you get it working like this:
>  a Dictionary('error'->'' 'icc'->true 'lhs'->'1 Brazil real' 'rhs'->'0.592768 U.S. dollars' )
> sebastian <http://about.me/sebastianconcept>
> o/
>
>
>

--
Lukas Renggli
www.lukas-renggli.ch

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: json parser patch

Philippe Marschall
In reply to this post by sebastianconcept@gmail.co
2011/9/12 Sebastian Sastre <[hidden email]>:
> Maybe this is useful to someone:
> Try this:
> JSJsonParser parseStream: '{lhs: "1 Brazil real",rhs: "0.592768 U.S.
> dollars",error: "",icc: true}' readStream
> it can't parse that, so..

Because it's not JSON. JSON keys need to be quoted [1]

 [1] http://json.org/

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: json parser patch

sebastianconcept@gmail.co
Lukas, Phillipe,

sure? 

I see it says:
"...A value can be a string in double quotes, or a number, or true or false or null, or an object or an array..."

which translates to:
1. A value, like when value means something different than a key
2. can, like when can means something more flexible than a has to

I am missing something?




On Sep 12, 2011, at 2:28 PM, Philippe Marschall wrote:

2011/9/12 Sebastian Sastre <[hidden email]>:
Maybe this is useful to someone:
Try this:
JSJsonParser parseStream: '{lhs: "1 Brazil real",rhs: "0.592768 U.S.
dollars",error: "",icc: true}' readStream
it can't parse that, so..

Because it's not JSON. JSON keys need to be quoted [1]

[1] http://json.org/

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside





_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: json parser patch

Boris Popov, DeepCove Labs (SNN)

In JSON keys in an object can only be strings, but your example has no quotes around them, thus, it’s not valid JSON. Instead, try,

 

JSJsonParser parse: '{"lhs": "1 Brazil real","rhs": "0.592768 U.S. dollars","error": "","icc": true}'

 

Dictionary ('error' -> '' 'lhs' -> '1 Brazil real' 'rhs' -> '0.592768 U.S. dollars' 'icc' -> true)

 

HTH,

 

-Boris

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Sebastian Sastre
Sent: Monday, September 12, 2011 1:47 PM
To: Seaside - general discussion
Subject: Re: [Seaside] json parser patch

 

Lukas, Phillipe,

 

sure? 

 

I see it says:

"...A value can be a string in double quotes, or a number, or true or false or null, or an object or an array..."

 

which translates to:

1. A value, like when value means something different than a key

2. can, like when can means something more flexible than a has to

 

I am missing something?

 

 

 

 

On Sep 12, 2011, at 2:28 PM, Philippe Marschall wrote:



2011/9/12 Sebastian Sastre <[hidden email]>:

Maybe this is useful to someone:

Try this:

JSJsonParser parseStream: '{lhs: "1 Brazil real",rhs: "0.592768 U.S.

dollars",error: "",icc: true}' readStream

it can't parse that, so..


Because it's not JSON. JSON keys need to be quoted [1]

[1] http://json.org/

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

 

 

 

 


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: json parser patch

sebastianconcept@gmail.co
In reply to this post by sebastianconcept@gmail.co
ok, it seems it actually needs double quotes:
http://json.org/example.html

funny thing... I'm seeing "invalid" json being used all around

not to mention that the source I've shown, came from Google itself

Hmmm




On Sep 12, 2011, at 2:46 PM, Sebastian Sastre wrote:

Lukas, Phillipe,

sure? 

I see it says:
"...A value can be a string in double quotes, or a number, or true or false or null, or an object or an array..."

which translates to:
1. A value, like when value means something different than a key
2. can, like when can means something more flexible than a has to

I am missing something?




On Sep 12, 2011, at 2:28 PM, Philippe Marschall wrote:

2011/9/12 Sebastian Sastre <[hidden email]>:
Maybe this is useful to someone:
Try this:
JSJsonParser parseStream: '{lhs: "1 Brazil real",rhs: "0.592768 U.S.
dollars",error: "",icc: true}' readStream
it can't parse that, so..

Because it's not JSON. JSON keys need to be quoted [1]

[1] http://json.org/

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside




_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside





_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: json parser patch

Boris Popov, DeepCove Labs (SNN)

Sebastian,

 

You must be confusing JavaScript with JSON, where the latter is only a subset of the former to serve as a data-interchange format.

 

http://seattlesoftware.wordpress.com/2008/01/08/javascript-vs-json/

 

HTH,

 

-Boris

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Sebastian Sastre
Sent: Monday, September 12, 2011 1:57 PM
To: Seaside - general discussion
Subject: Re: [Seaside] json parser patch

 

ok, it seems it actually needs double quotes:

http://json.org/example.html

 

funny thing... I'm seeing "invalid" json being used all around

 

not to mention that the source I've shown, came from Google itself

 

Hmmm

 

 

 

 

On Sep 12, 2011, at 2:46 PM, Sebastian Sastre wrote:



Lukas, Phillipe,

 

sure? 

 

I see it says:

"...A value can be a string in double quotes, or a number, or true or false or null, or an object or an array..."

 

which translates to:

1. A value, like when value means something different than a key

2. can, like when can means something more flexible than a has to

 

I am missing something?

 

 

 

 

On Sep 12, 2011, at 2:28 PM, Philippe Marschall wrote:



2011/9/12 Sebastian Sastre <[hidden email]>:

Maybe this is useful to someone:

Try this:

JSJsonParser parseStream: '{lhs: "1 Brazil real",rhs: "0.592768 U.S.

dollars",error: "",icc: true}' readStream

it can't parse that, so..


Because it's not JSON. JSON keys need to be quoted [1]

[1] http://json.org/

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

 

 

 

 

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside




 


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside