Rewrite to be based off of json2.js

Not all JavaScript environments keep objects in original key order, so
we can't reliably serialize objects in sorted key order merely by
creating object with keys in sorted order :-)