Skip to content

Serializes unicode strings differently than JSON.stringify #84

@justin-together

Description

@justin-together

JSONbig.stringify escapes '\u202c' while JSON.stringify does not:

Welcome to Node.js v16.20.0.
Type ".help" for more information.
> JSONbig = require('json-bigint')
[Function (anonymous)] {
  parse: [Function (anonymous)],
  stringify: [Function (anonymous)]
}
> x = { k: 'a\u202cz' }
{ k: 'a‬z' }
> [...JSON.stringify(x)].map(i => i.charCodeAt(0).toString(16))
[
  '7b', '22',   '6b',
  '22', '3a',   '22',
  '61', '202c', '7a',
  '22', '7d'
]
> [...JSONbig.stringify(x)].map(i => i.charCodeAt(0).toString(16))
[
  '7b', '22', '6b', '22',
  '3a', '22', '61', '5c',
  '75', '32', '30', '32',
  '63', '7a', '22', '7d'
]
>

Note the absence of 202c. In its place is the escaped string "\u202c".

More parameters controlling escaping would be helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions