Strips single-line (//) and multi-line (/* ... */) comments and trailing commas from a JSONC string. Preserves URLs and slashes within quoted strings.
//
/* ... */
The JSONC formatted string to strip
Cleaned JSON string ready for JSON.parse
JSON.parse
const cleanJson = stripJSONC('{\n // comment\n "key": "value",\n}'); Copy
const cleanJson = stripJSONC('{\n // comment\n "key": "value",\n}');
Strips single-line (
//) and multi-line (/* ... */) comments and trailing commas from a JSONC string. Preserves URLs and slashes within quoted strings.