5 stable releases

1.0.4 Jul 21, 2024
1.0.3 Jul 20, 2024
1.0.2 Feb 3, 2024
1.0.1 Jan 19, 2024

#365 in Parser implementations

Download history 15345/week @ 2024-08-19 20185/week @ 2024-08-26 14567/week @ 2024-09-02 15946/week @ 2024-09-09 13726/week @ 2024-09-16 18118/week @ 2024-09-23 24044/week @ 2024-09-30 10366/week @ 2024-10-07 20845/week @ 2024-10-14 14781/week @ 2024-10-21 19585/week @ 2024-10-28 8964/week @ 2024-11-04 35075/week @ 2024-11-11 38221/week @ 2024-11-18 14962/week @ 2024-11-25 32939/week @ 2024-12-02

121,681 downloads per month
Used in 87 crates (5 directly)

MIT license

18KB
396 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

Dependencies

~250KB