Crates.io | json_parser_with_pest |
lib.rs | json_parser_with_pest |
version | 1.1.0 |
source | src |
created_at | 2024-11-16 08:46:22.282141 |
updated_at | 2024-11-16 08:51:04.320788 |
description | A JSON parser created in Rust using Pest grammar. |
homepage | |
repository | |
max_upload_size | |
id | 1450241 |
size | 79,319 |
https://docs.rs/json_parser_with_pest/latest/json_parser_with_pest/
https://crates.io/crates/json_parser_with_pest
json_parser_with_pest is a JSON processing tool written in Rust, capable of parsing JSON files, validating schemas, and converting JSON to various formats like YAML and XML. Built with Pest for grammar parsing, this parser supports the manipulation of JSON files with a command-line interface (CLI).
The parser utilizes a custom-defined Pest grammar file (json.pest
) to interpret JSON structures. Key parsing rules are defined for JSON objects, arrays, strings, numbers, booleans, and null values, enabling support for typical JSON formats with whitespace tolerance and escape sequences in strings.
This diagram illustrates the general structure of JSON supported by this parser:
json
├── object
│ ├── pair
│ │ ├── string (key)
│ │ ├── value
│ │ │ ├── object
│ │ │ ├── array
│ │ │ ├── string
│ │ │ ├── number
│ │ │ ├── boolean
│ │ │ └── null
│ │ └── ...
├── array
│ ├── value
│ └── ...
└── other basic JSON values (string, number, boolean, null)
{}
, where keys are strings and values can be any JSON type.[]
, allowing mixed types.\n
, \t
, Unicode).true
, false
, and null
.Run the parser through CLI commands, such as:
$ zaporozhets-json-parser validate <input> <schema>
$ zaporozhets-json-parser parse-partial <input> <key>
$ zaporozhets-json-parser edit <input> <key> <value>
Use --help
for full command options.
validate
: Validates JSON against a schema.parse-partial
: Extracts a specified key's value.edit
: Updates a key in the JSON.convert
: Converts JSON to YAML or XML.large-file
: Parses large JSON files in chunks.cargo build
Error handling is implemented with anyhow
for flexible context-based error reporting, and thiserror
for custom error types like JsonParseError
and SchemaValidationError
.
tests
directory, covering each grammar rule.cargo fmt
and cargo clippy
to maintain code quality.The Makefile
includes commands to simplify running, testing, formatting, and linting the project:
run:
cargo run
release:
cargo run --release
build:
cargo build
build-release:
cargo build --release
test:
cargo test
format:
cargo fmt
lint:
cargo clippy -- -D warnings
precommit: format lint test
clean:
cargo clean
update:
cargo update