There's a small inconsistency between the current documentation for
JSON.stringify() and the actual implementation (v. 2008-07-09) . The
documentation for the replacer argument says:
an optional parameter that determines how object
values are stringified for objects without a toJSON
method. It can be a function or an array.
AFAICT, the actual implementation always calls a toJSON method if it
exists, and then passes the return value from that call to the
replacer. The value returned from the replacer is the one serialized.
So the replacer determines how all objects are serialized, not just
those without a toJSON() method.
I'd prefer an implementation that did *not* call toJSON() if a
replacer function is specified. If the replacer wants to call toJSON()
itself, it can, but the call isn't required. This way, the caller of
JSON.stringify() may be able to avoid passing the flow of control to
an object in the serialized object tree. The "may" depends on the use
I'd also prefer that no newline character be inserted between elements
in an array. When using the Firebug "Net" pane, the current
implementation requires scrolling for even short payloads. I like
having the newline between object members though. For some reason, my
arrays tend to be longer lists of literals, whereas object members are
more likely to be objects.