help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] Re: JSON Dumper/Parser


From: Robin Redeker
Subject: Re: [Help-smalltalk] Re: JSON Dumper/Parser
Date: Sat, 18 Aug 2007 16:32:40 +0200
User-agent: Mutt/1.5.11+cvs20060403

On Wed, Aug 08, 2007 at 03:10:14PM +0200, Paolo Bonzini wrote:
> 
> >   -  Maybe also the datatypes for json objects and arrays could be made 
> >   configurable
> >      somehow. It's currently limited to generating Dictionary and 
> >      OrderedCollection
> >      from a JSON string.
> >      The dumping works for Dictionaries and SequenceableCollection.
> >
> >So, before the code gets lost I've attached it to this mail (json.st).
> >
> >There are some comments in the code and I hope it's mostly understandable.
> 
> I've fixed most issues except the one above.

Thanks alot! I guess the above is just a minor nice-to-have
feature. The other problems were more serious IMO.

> In addition, I changed your code so that: 1) for reading, the lexer 
> *uses* a stream instead of subclassing it; the stream is in an instance 
> variable, so that the reading happens in the instance side of the 
> JSONReader class;

Sounds great, I'm not that used to smalltalk programming after all.

> 2) the writing is done to a stream, which eliminates 
> the need to construct temporary streams in toJSON.

Yay!

> There was one bug: the code was subject to infinite loops in the 
> presence of invalid JSON input such as '2.5d'.

Oh, thats bad.

> While I don't have time to make it into a real gst package, it will be 
> done in due time (especially if somebody gets an idea on how to 
> implement generating other classes than dictionaries).

Wouldn't it be enough to add some methods to JSONReader that return
objects for storing array and json-objects. eg. like:


   !JSONReader methodsFor: 'private'!

   make_array
      ^OrderedCollection new.

And then something like:

   !JSONReader methodsFor: 'private'~

   nextJSONArray
      | c obj value |
      obj := self make_array.
      ...

Then the objects returned by make_array and make_object have to
implement the right methods (interfaces of Collection and Dictionary
types should be enough).

There is another minor "issue", I've recently read the JSON spec
more carefully and saw that fromJSON only needs to parse a JSON object,
that means that fromJSON shouldn't accept a string like '4' or
'["fef"]', but only something like this '{"a":"b"}'.


Robin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]