couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Anderson <>
Subject Re: upgrading to json2.js
Date Tue, 26 Jan 2010 04:08:08 GMT
On Tue, Dec 22, 2009 at 10:26 AM, Chris Anderson <> wrote:
> On Sat, Dec 19, 2009 at 5:07 PM, Chris Anderson <> wrote:
>> It's well known that in order to take advantage of native JSON
>> libraries in the newest Mozilla JavaScript VMs, we'll need to change
>> our handling of 'undefined' in the toJSON() routine.
>> I propose we make this change now, by replacing our current JSON
>> handling with json2.js, the current reference implementation.
>> I've started the work here:
> I've update my json2 branch to reflect my latest commits to trunk.

I've committed this change to CouchDB. It will appear in the 0.11
release. From the commit message:

 Replace the old JavaScript query server JSON library with json2.js

    This change makes us interoperate better with other JSON
implementations. It also means we can use the native JSON handlers in
JavaScript runtimes that support them.

    There are some potential breaking changes for apps that depend on
Couch blowing up on 'undefined'. json2.js serializes undefined as
'null' instead of crashing.

    This change will also effect people using E4X, as you can't just
return an XML object and have it serialized to a string for you.
Calling .toXMLString() on these is what you need to do here.


> Benoit has fixed the E4X issues. There are a few other test failures
> which I believe have to do with the changed behavior. If anyone wants
> to take a look at these and consider changing the tests where
> appropriate, that'd be super helpful.
> Chris
>> Everything works except E4X. When I run the view_xml tests, I see this
>> error in the logs:
>> OS Process :: function raised exception (TypeError:
>> String.prototype.toJSON called on incompatible XML) with doc._id
>> 43840f81289e03fec4e9f620b2c03799
>> In our old implementation of toJSON, we run value.toXMLString() to
>> convert XML to strings. json2.js takes a callback parameter to allow
>> modification of results, but the TypeError is triggered before the
>> callback, it seems.
>> If any of you JavaScript ninjas wanna give this a shot, please help me
>> finish it.
>> Chris
>> --
>> Chris Anderson
> --
> Chris Anderson

Chris Anderson

View raw message