Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ module.exports = function (source, reviver) {
var v;
var val = holder[key];
if (val && typeof val === 'object') {
for (k in value) {
for (k in val) {
if (Object.prototype.hasOwnProperty.call(val, k)) {
v = walk(val, k);
if (typeof v === 'undefined') {
Expand Down
18 changes: 18 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,21 @@ test('parse', function (t) {

t.end();
});

test('parse with reviver', function (t) {
var data = '{"a": {"b": 2}}';
var calls = [];

json.parse(data, function reviver(key, value) {
calls[calls.length] = key;
return value;
});

t.deepEqual(
calls.sort(),
['', 'a', 'b'].sort(),
'reviver is called for all nested properties'
);

t.end();
});
Loading