Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON.parse is different in Node and Chrome?

code :
JSON.parse('{"a":"\\\\"}');

node: { a: '\\' }
chrome: {a: "\"}

Why it behaves different between Node and Chrome? I've check the v8 version of them and both are 5.x, it's weird.

like image 767
ParallelZebra Avatar asked Oct 17 '25 07:10

ParallelZebra


1 Answers

It's just a difference in the presentation of the object contents by the console implementations. If you do

console.log(JSON.parse('{"a":"\\\\"}').a.length)

in both environments you correctly get 1.

The Node console seems to want to show you the object contents such that you could re-create the object with cut-and-paste. The Chrome console just shows the single backslash, but there's just one backslash for real in both environments.

like image 82
Pointy Avatar answered Oct 19 '25 21:10

Pointy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!