As you may have guessed, or may not have if you haven't been keeping up, I'm a huge fan of JSON, especially as an alternative to XML for web apps. I'm also a big fan of the prototype.js library.
If you use a json library that extends the Object prototype, such as the one at json.org you run into problems.
Object.prototype is verboten, for a variety of reasons, but mostly because extending the Object prototype will cause all kinds of things to break.
There should be an exception for JSON, however, because the Object prototype will be extended this year to include the Object.toJSONString (along with extensions to the Array prototype, String prototype, etc.) as part of the fourth edition of the ECMA Standard. There will also be a migration towards class based inheritance which has the potential of destroying months of my work if they take it too far, or by saving months of work if they do it just right. But I digress. Here's the solution for making prototype.js compatible with json.js and essentially any other Object.prototype functional extensions.
In prototype 1.5, scroll down to line 915. If you can't go directly to a line number in your editor, search for the phrase "for (var name in headers)" (minus the quotes).
between line 915 and 916, insert this line:
if (typeof headers[name] != 'function')
so that it looks like this:


1<br />
2 for (var name in headers)<br />
3 if (typeof headers[name] != 'function') //Added by Steve Kallestad for compatibility with json.js<br />
4 this.transport.setRequestHeader(name, headers[name]);<br />Essentially, this removes any functions from the header grouping, which should be done in the first place, but with 2500+ lines of code, there are bound to be a few things for us to complain about. (Don't get me started on class inheritance...)
There you go. A one line update that could take quite a while to troubleshoot.
Join The Making Prototype Compatible with json.js Discussion
