jsonc_parser

Function parse_to_ast

Source
pub fn parse_to_ast<'a>(
    text: &'a str,
    collect_options: &CollectOptions,
    parse_options: &ParseOptions,
) -> Result<ParseResult<'a>, ParseError>
Expand description

Parses a string containing JSONC to an AST with comments and tokens.

ยงExample

use jsonc_parser::CollectOptions;
use jsonc_parser::CommentCollectionStrategy;
use jsonc_parser::parse_to_ast;
use jsonc_parser::ParseOptions;

let parse_result = parse_to_ast(r#"{ "test": 5 } // test"#, &CollectOptions {
    comments: CommentCollectionStrategy::Separate, // include comments in result
    tokens: true, // include tokens in result
}, &Default::default()).expect("Should parse.");
// ...inspect parse_result for value, tokens, and comments here...