We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 82b5eab commit c1de9d1Copy full SHA for c1de9d1
index.js
@@ -39,7 +39,10 @@ module.exports = function (obj, opts) {
39
throw new TypeError('Converting circular structure to JSON');
40
}
41
else seen.push(node);
42
-
+
43
+ if (node.toJSON && typeof node.toJSON === 'function') {
44
+ node = node.toJSON();
45
+ }
46
var keys = objectKeys(node).sort(cmp && cmp(node));
47
var out = [];
48
for (var i = 0; i < keys.length; i++) {
test/to-json.js
@@ -0,0 +1,8 @@
1
+var test = require('tape');
2
+var stringify = require('../');
3
4
+test('toJSON function', function (t) {
5
+ t.plan(1);
6
+ var obj = { one: 1, two: 2, toJSON: function() { return { one: 1 }; } };
7
+ t.equal(stringify(obj), '{"one":1}' );
8
+});
0 commit comments