QuietJSON
Silent Data Corruption Warning

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.

Warning: String appears to contain a Windows file path ("C:\temp\notes.txt") where single backslashes may have been interpreted as escape sequences (\t = tab, \n = newline). Use double backslashes ("C:\\\\temp\\\\notes.txt").

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 → \t becomes a horizontal tab.
  • C:\notes → \n becomes a line break (newline).
  • C:\reports → \r becomes a carriage return.
  • C:\bin → \b becomes 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

Corrupted (Single Backslash):
{
  "logDir": "C:\temp\logs",
  "output": "D:\notes\export.csv"
}
Correct (Escaped Double Backslash):
{
  "logDir": "C:\\temp\\logs",
  "output": "D:\\notes\\export.csv"
}
Pro Tip: Modern Windows systems (Windows 10/11, PowerShell, and Node.js) natively support forward slashes in path APIs: "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.

Validate Paths →