Expand description
CST for manipulating JSONC.
§Example
use jsonc_parser::cst::CstRootNode;
use jsonc_parser::ParseOptions;
use jsonc_parser::json;
let json_text = r#"{
// comment
"data": 123
}"#;
let root = CstRootNode::parse(json_text, &ParseOptions::default()).unwrap();
let root_obj = root.object_value_or_set();
root_obj.get("data").unwrap().set_value(json!({
"nested": true
}));
root_obj.append("new_key", json!([456, 789, false]));
assert_eq!(root.to_string(), r#"{
// comment
"data": {
"nested": true
},
"new_key": [456, 789, false]
}"#);
Macros§
Structs§
- Represents an array that may contain elements (ex.
[]
,[1, 2, 3]
). - Boolean (
true
orfalse
). - Newline character (Lf or crlf).
- Null keyword (
null
). - Object literal that may contain properties (ex.
{}
,{ "prop": 4 }
). - Property in an object (ex.
"prop": 5
). - Root node in the file.
- Text surrounded in double quotes (ex.
"my string"
). - Insigificant token found in the file (ex. colon, comma, brace, etc.).
- Blank space excluding newlines.
- Property key that is missing quotes (ex.
prop: 4
).
Enums§
- Enumeration of a node that has children.
- API user provided value for inserts and replaces.
- Enumeration of a node that has no children.
- Kind of newline.
- All the different kinds of nodes that can appear in the CST.
- An object property name that may or may not be in quotes (ex.
"prop"
in"prop": 5
). - Mode to use for trailing commas.