Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
134
rated 0 times [  136] [ 2]  / answers: 1 / hits: 47627  / 10 Years ago, tue, december 2, 2014, 12:00:00

Javascript uses as far as I know UTF-16 fundamentally as a standard for strings. With JSON.stringify() I can create a JSON string from an object.



Is that JSON string UTF-16 encoded?



Can I convert (hopefully fast) that string to UTF-8 to save bandwidth for huge files (1MB JSON)?


More From » json

 Answers
53

JavaScript engines are allowed to use either UCS-2 or UTF-16.




So, yes, JSON.stringify() will return a string in whatever encoding your implementation uses for strings. If you were to find a way to change that encoding within the context of your script, it would no longer be a valid JavaScript string.



For serialising it over a network, though, I would expect it to automatically be transcoded into the character set of the HTTP request (assuming you're talking about HTTP). So if you send it via HTTP POST with a character set of UTF-8, your browser should transparently handle the transcoding of that data before it is sent.



Otherwise browsers would really struggle with character set handling.


[#68619] Sunday, November 30, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cortez

Total Points: 326
Total Questions: 106
Total Answers: 110

Location: Slovenia
Member since Wed, Apr 6, 2022
2 Years ago
;