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
121,681 downloads per month
Used in 87 crates
(5 directly)
18KB
396 lines
JSON Strip Comments
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