According to this question JSON is automatically written using surrogate pairs.
However, this is not my experience.
Using Node 6.9.2
and the following code my file still shows characters not encoded using surrogate pairs.
const fs = require('fs')
const infile = fs.readFile('raw.json', 'utf8', (err, data) => {
if (err) {
throw err
}
data = JSON.stringify(data)
fs.writeFile('final.json', data, 'utf8', (err) => {
if (err) {
throw err
}
console.log('done')
})
})
In my editor, which must have good unicode and use and a font that has glyphs for these characters, the contents of the file raw.json
have characters such as "題"
That character still appears in final.json
(no change is made).
Additionally I tried switching the encoding utf8
to utf16le
for the file being written but nothing changed.
Is there a way to force using surrogate pairs?