Remove comments from JSON

Remove JSONC comments and trailing commas so a commented configuration becomes strict JSON.

freeworks offlinenothing uploaded
ToolJSONC Stripper
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

A character scanner tracks quoted strings and removes line and block comments only outside strings. It drops commas before closing braces or brackets, then parses the result as strict JSON.

  • Line and block comments cover tsconfig and editor settings.
  • Trailing-comma removal bridges JSONC input to strict JSON parsers.

Worked example

Server config with inline and block comments
Remove comments from a JSONC file to produce valid JSON
Input
											{
  // Server config
  "host": "localhost",
  "port": 3000 /* default port */
}
										
Output
												{
  
  "host": "localhost",
  "port": 3000 
}
											

When to use this

tsconfig.json, .vscode/settings.json, and build-time configuration conversion use JSONC.

Edge cases

  • http://example.test inside quotes keeps its slashes.
  • A multi-line block comment is removed without consuming the following token.
  • A comma inside a string remains while a comma before ] or } is removed.

References