[cl-json-devel] Parsing JavaScript data

Henrik Hjelte henrik at evahjelte.com
Tue Jun 10 14:04:57 UTC 2008


On Tue, Jun 10, 2008 at 2:00 PM, Andrei Stebakov <lispercat at gmail.com> wrote:
> I was sending the string I mentioned starting with "var Categories = ....".

ok, that was javascript source code, not json.
When it is evaluated, it becomes a javascript array.
That array can be encoded to Json, for that you need
a javascript library to do the encoding.
Look at www.json.org for a description of json and for available
libraries, I believe that
all major javascript frameworks have a json encoder.

For example if you have prototype it adds a method to all arrays:

var hello=[{a:2,b:3}];
console.log(hello.toJSON());

>>> var hello=[{a:2,b:3}]; console.log(hello.toJSON());
[{"a": 2, "b": 3}]
(output from Firebug, not the quotes around a and b when it is JSON)

> Looks like I somehow need to translate the Categories and DB to some json
> tree, but I don't know how to do it.

I would look at the test cases for cl-json, they explain fairly well
how to do encoding
and decoding.

> Should I resort to flex/bison or I can just use the libraries
> available for common lisp?

I don't know anything about flex or bison. But I say it is early to
give up at this state,
so far the problem has not been with cl-json.

Good luck,
Henrik



More information about the cl-json-devel mailing list