JSON syntax allows four whitespace characters
RFC 8259 allows U+0020, tab U+0009, line feed U+000A and carriage return U+000D as syntax whitespace. NBSP, U+00A0, is not on that list. Moyoutil’s formatJSON accepts an ordinary space after the colon but rejects NBSP. The code’s \u notation is a JavaScript string escape that creates the character at runtime.
formatJSON('{"n":\u00201}'); // accepted
formatJSON('{"n":\u00A01}'); // throwsNBSP inside a string is data
Inside double quotes, NBSP is a valid string character in this example. Moyoutil formatting and minification preserve it. Replacing NBSP throughout the source with ordinary spaces changes the code point between A and B from 160 to 32. Do not replace spaces inside data indiscriminately while repairing syntax.
const source = '{"text":"A\u00A0B"}';
JSON.parse(formatJSON(source, 0).output).text.codePointAt(1) // 160
JSON.parse(source.replaceAll("\u00A0", " ")).text.codePointAt(1) // 32Use the JSON tool’s error line, column and jump-to-error control to inspect nearby characters. Keep the original, retype invalid whitespace outside strings as intended syntax whitespace, and validate again. The tool has no dedicated NBSP detection or automatic repair. Passing syntax validation does not validate a receiving API’s schema.
Frequently Asked Questions
Will minification repair invalid whitespace?
No. formatJSON checks syntax before producing output, so minification also rejects NBSP outside strings. NBSP inside a string remains after formatting or minification.