13 releases (5 breaking)

Uses new Rust 2021

0.6.0 Sep 9, 2022
0.5.0 Aug 18, 2022
0.4.0 Aug 10, 2022
0.3.0 Aug 9, 2022
0.1.10 Oct 30, 2020

#422 in Parser implementations

Download history 79/week @ 2022-06-02 7/week @ 2022-06-09 10/week @ 2022-06-16 6/week @ 2022-06-23 6/week @ 2022-06-30 22/week @ 2022-07-07 15/week @ 2022-07-14 34/week @ 2022-07-21 24/week @ 2022-07-28 60/week @ 2022-08-04 57/week @ 2022-08-11 58/week @ 2022-08-18 32/week @ 2022-08-25 25/week @ 2022-09-01 117/week @ 2022-09-08 26/week @ 2022-09-15

201 downloads per month
Used in 8 crates (7 directly)

MIT/Apache

155KB
4.5K SLoC

JSONA CLI

A JSONA parser, analyzer and formatter library. More information on the website.


lib.rs:

About

The main purpose of the library is to provide tools for analyzing JSONA data where the layout must be preserved and the original position of every parsed token must be known. It can also format JSONA documents.

It uses Rowan for the syntax tree, and every character is preserved from the input, including all comments and white space.

A DOM can be constructed for data-oriented analysis where each node wraps a part of the syntax tree with additional information and functionality.

Features

  • serde: Support for serde serialization of the DOM nodes.

Usage

A JSONA document has to be parsed with parse first, it will build a syntax tree that can be traversed.

If there were no syntax errors during parsing, then a [dom::Node] can be constructed. It will build a DOM tree and validate the JSONA document according to the specification. A DOM tree can be constructed even with syntax errors present, however parts of it might be missing.

use jsona::parser::parse;
const SOURCE: &str = r#"
{
  createPost: { @describe("Create a blog post") @mixin(["createPost", "auth1"])
    req: {
      body: {
        content: "paragraph", @mock
      }
    },
    res: {
      body: {
        id: 0, @type
        userId: 0, @type
        content: "", @type
      }
    }
  }
}
"#;

let parse_result = parse(SOURCE);

// Check for syntax errors.
// These are not carried over to DOM errors.
assert!(parse_result.errors.is_empty());

let root_node = parse_result.into_dom();

Dependencies

~1.6–2.4MB
~49K SLoC