Skip to content

Instantly share code, notes, and snippets.

@mitsuhiko
Created November 7, 2018 22:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mitsuhiko/7e784becb001225ae7df7df15b93512f to your computer and use it in GitHub Desktop.
<!doctype html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prototype/1.6.0/prototype.min.js"></script>
<script>
(function() {
var originalStringify = JSON.stringify;
JSON.stringify = function stringify() {
var old = Array.prototype.toJSON;
delete Array.prototype.toJSON;
try {
return originalStringify.apply(this, arguments);
} finally {
Array.prototype.toJSON = old;
}
}
})();
console.log(JSON.stringify({"foo": [1, 2, 3]}));
console.log(typeof JSON.parse(JSON.stringify([1])) === 'string' ? 'buggy' : 'not buggy');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment