Skip to main content

strip_jsonc_comments

Function strip_jsonc_comments 

Source
pub fn strip_jsonc_comments(src: &str) -> String
Expand description

Strip JSONC-style comments from src while preserving string literals byte-exact. Handles:

  • // line comments through end-of-line
  • /* block comments */ (non-nested, which matches standard JSONC)
  • Escape-aware string parsing so "//" inside a string is not stripped

Returns a string suitable for serde_json::from_str. Does not attempt to preserve or round-trip the comments — callers that need to write the file back must be explicit about losing comments.