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 "ー" ?
>Solution :
Then why "\u30FC" is converted to "ー" ?
- The JavaScript engine reads your string literal and does that conversion to create the in-memory string
- The object containing that string is passed to
JSON.stringify JSON.stringifyencodes the object as JSON and represents theーas a literalーbecauseJSON.stringifywas written in such a way to prefer literal characters over escape sequences where the JSON data format allows either.