Windows File Paths & Backslash Escapes in JSON
One of the most devious JSON bugs occurs when copying Windows folder paths into configuration files. Single backslashes can turn your folder names into tabs or newlines without throwing a syntax error.
The "Accidental Escape" Trap
In RFC 8259, a backslash (\) instructs the parser to treat the following character as a special control code. If a Windows folder begins with certain letters, the backslash forms a valid JSON escape:
C:\temp→\tbecomes a horizontal tab.C:\notes→\nbecomes a line break (newline).C:\reports→\rbecomes a carriage return.C:\bin→\bbecomes a backspace.
Because \t and \n are valid JSON escape sequences, standard JSON validators report that the file is 100% valid! But when your application reads the file path from configuration, the file cannot be found because the path string has been corrupted into C:[TAB]emp.
Correcting Windows Paths in JSON
"logDir": "C:\temp\logs",
"output": "D:\notes\export.csv"
}
"logDir": "C:\\temp\\logs",
"output": "D:\\notes\\export.csv"
}
"C:/temp/logs" works identically and requires no backslash escaping.Frequently Asked Questions
Why does "C:\temp" break or corrupt in JSON?
In JSON (RFC 8259), a backslash (\) is the escape character. When followed by 't', \t represents an ASCII horizontal tab character, not a backslash and the letter 't'. Thus, "C:\temp" is parsed as 'C:' followed by a literal tab followed by 'emp'.
What happens if a Windows path has an invalid escape like "C:\Users"?
In strict JSON, \U is an invalid escape sequence (only lowercase \u followed by 4 hexadecimal digits is valid for unicode). A strict JSON parser will immediately throw a SyntaxError: Bad escaped character in JSON.
How should Windows file paths be formatted in JSON?
Every backslash must be doubled: "C:\\Users\\Alice\\Documents\\file.txt". Alternatively, modern Windows APIs and Node.js accept forward slashes: "C:/Users/Alice/Documents/file.txt".
Detect silent Windows path corruption
QuietJSON proactively warns you when strings contain single-backslash Windows paths.