[][src]Function json_comments::strip_comments

Important traits for StripComments<T>
pub fn strip_comments<T: Read>(input: T) -> StripComments<T>

Transform a input so that it changes all comments to spaces so that a downstream json parser (such as json-serde) doesn't choke on them.

The supported comments are:

  • C style block comments (/* ... */)
  • C style line comments (// ...)
  • Shell style line comments (# ...)

Example

use json_comments::strip_comments;
use std::io::Read;

let input = r#"{
// c line comment
"a": "comment in string /* a */",
# shell line comment
} /** end */"#;

let mut stripped = String::new();
strip_comments(input.as_bytes()).read_to_string(&mut stripped).unwrap();

assert_eq!(stripped, "{
                 \n\"a\": \"comment in string /* a */\",
                    \n}           ");