From the MDN documentation about JSON.parse :
The examiner is ultimately called with an empty string and the highest value to allow conversion of the highest value.
Parsing {"id":"1","name":"2"} will create a JavaScript object. Therefore, at the last call to the reviver key function, the empty string is val , and val is the generated object.
The default string representation for any object is [object Object] , so the output you get is not surprising.
Here is a simpler example:
// object vv alert('Object string representation: ' + {});
Usually you use the reviver function if you want to immediately convert the analyzed data. You can simply:
var obj = JSON.parse(json);
and then iterate over the object or directly access its properties. See Access / process (nested) objects, arrays, or JSON for more information.
source share