I’m trying to adapt JSON.Parse() for NaN.
console.log(JSON.parse('{"n": 1}'));
console.log(JSON.parse('{"n": NaN}'));
1st one is {n:1}.
2nd one has an error which says Unexpected token N in JSON
.
And I want to change NaN to 0
like {n: 0}
.
I found a resource which create JSON Parser from scratch.https://lihautan.com/json-parser-with-javascript/#implementing-the-parser
It’s good he separates keys and values so that I can check only values if there is NaN and fix it.
But the problem is I have no idea where I can put the NaNParser() and the process. Because the parameter looks coming 1 by 1 character.
If you could give me some advice, it really helps me.
https://codesandbox.io/s/json-parser-with-error-handling-hjwxk?from-embed