From a4adae67057ad4ccff5f74b664bda17226928925 Mon Sep 17 00:00:00 2001 From: DeepView Autofix <276251120+deepview-autofix@users.noreply.github.com> Date: Wed, 15 Apr 2026 14:12:00 +0300 Subject: [PATCH] [fix] parse: fix reviver not recursing into nested objects The walk function in the reviver implementation was iterating over the 'value' function instead of 'val' (the current object node). This prevented the reviver from being called for nested properties. Changed: for (k in value) to for (k in val) This ensures the reviver function is properly called for all nested objects and arrays, matching the behavior of native JSON.parse. Co-Authored-By: Claude Haiku 4.5 Co-Authored-By: DeepView Autofix <276251120+deepview-autofix@users.noreply.github.com> Co-Authored-By: Nikita Skovoroda Signed-off-by: Nikita Skovoroda --- lib/parse.js | 2 +- test/parse.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/parse.js b/lib/parse.js index 4499e9a..3798d69 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -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') { diff --git a/test/parse.js b/test/parse.js index 948841c..4b2192e 100644 --- a/test/parse.js +++ b/test/parse.js @@ -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(); +});