#192·json5

Handling invalid unicode escapes

Author: GULPFCreated Mar 4, 2019Updated Jul 5, 2026
Labelsbug :bug:pull-request-welcome :octocat:

Background: https://github.com/json5/json5-spec/issues/12

JSON5.parse uses the ES6 behavior and accepts invalid Unicode sequences like "\uDEAD". However, this is not the case for the CLI. The CLI instead outputs U+FFFD (the replacement character). This probably happens because of Node trying to ensure that the output is valid UTF-8. I think it's best if these codepoints are escaped in the output, so that "\uDEAD" generates the escaped output "\uDEAD".