Module cst

Source
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§

json

Structs§

CstArray
Represents an array that may contain elements (ex. [], [1, 2, 3]).
CstBooleanLit
Boolean (true or false).
CstComment
CstNewline
Newline character (Lf or crlf).
CstNullKeyword
Null keyword (null).
CstNumberLit
CstObject
Object literal that may contain properties (ex. {}, { "prop": 4 }).
CstObjectProp
Property in an object (ex. "prop": 5).
CstRootNode
Root node in the file.
CstStringLit
Text surrounded in double quotes (ex. "my string").
CstToken
Insigificant token found in the file (ex. colon, comma, brace, etc.).
CstWhitespace
Blank space excluding newlines.
CstWordLit
Property key that is missing quotes (ex. prop: 4).

Enums§

CstContainerNode
Enumeration of a node that has children.
CstInputValue
API user provided value for inserts and replaces.
CstLeafNode
Enumeration of a node that has no children.
CstNewlineKind
Kind of newline.
CstNode
All the different kinds of nodes that can appear in the CST.
ObjectPropName
An object property name that may or may not be in quotes (ex. "prop" in "prop": 5).
TrailingCommaMode
Mode to use for trailing commas.