3 stable releases

1.0.2 Feb 3, 2024
1.0.1 Jan 19, 2024

#573 in Parser implementations

Download history 427/week @ 2024-01-17 1129/week @ 2024-01-24 1749/week @ 2024-01-31 1062/week @ 2024-02-07 1401/week @ 2024-02-14 2082/week @ 2024-02-21 2084/week @ 2024-02-28 2671/week @ 2024-03-06 2751/week @ 2024-03-13 3221/week @ 2024-03-20 2743/week @ 2024-03-27 4334/week @ 2024-04-03 4688/week @ 2024-04-10 3674/week @ 2024-04-17

15,922 downloads per month
Used in 29 crates (2 directly)

MIT license

17KB
371 lines

JSON Strip Comments

Crates.io Docs.rs

A fork of a fork for stripping JSON comments and trailing commas in place:

Example

use serde_json::Value;

fn main() {
    let mut data = String::from(
        r#"
     {
         "name": /* full */ "John Doe",
         "age": 43,
         "phones": [
             "+44 1234567", // work phone
             "+44 2345678", // home phone
         ]
     }"#,
    );

    json_strip_comments::strip(&mut data).unwrap();
    let value: Value = serde_json::from_str(&data).unwrap();

    println!("{value}");
}

lib.rs:

Replace json comments and trailing commas in place.

A fork of a fork:

json-strip-comments is a library to strip out comments from JSON. By processing text through a StripComments adapter first, it is possible to use a standard JSON parser (such as serde_json with quasi-json input that contains comments.

In fact, this code makes few assumptions about the input and could probably be used to strip comments out of other types of code as well, provided that strings use double quotes and backslashes are used for escapes in strings.

The following types of comments are supported:

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

Example

No runtime deps