Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why does JSON.stringify() \u30FC to ー

i tried below code:

console.log(JSON.stringify({ test: "\u30FCabc" }));

it gives below ouput

'{"test":"ーabc"}'

we know that mainly JSON.stringify() method converts a JavaScript object or value to a JSON string. And as per JSON std (https://www.json.org/json-en.html) we should be able to store \u30FC. Then why "\u30FC" is converted to "ー" ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Then why "\u30FC" is converted to "ー" ?

  1. The JavaScript engine reads your string literal and does that conversion to create the in-memory string
  2. The object containing that string is passed to JSON.stringify
  3. JSON.stringify encodes the object as JSON and represents the as a literal because JSON.stringify was written in such a way to prefer literal characters over escape sequences where the JSON data format allows either.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading