json_pest_parser is a Rust-based command-line tool that parses JSON files using the pest library. This parser converts JSON content into a structured format and can serialize the content back to JSON. It provides clear error messages for invalid inputs, making it a reliable tool for JSON validation and manipulation.
This project demonstrates a simple yet robust JSON parser built with pest, a parsing expression grammar library for Rust. The parser supports all standard JSON features, including objects, arrays, strings, numbers, booleans, and null values. It also provides a command-line interface for processing JSON files.
-
Parsing Process:
- The JSON grammar is defined in
grammar.pest
and adheres to the JSON specification. - The
parse_json_str
function validates and parses the JSON string into a structuredJsonContent
enum.
- The JSON grammar is defined in
-
Serialization:
- The
json_content_to_Str
function converts the parsedJsonContent
back into a JSON-formatted string.
- The
-
Error Handling:
- Handles invalid JSON formats and empty files with descriptive error messages.
To use this tool, clone the repository and build the project using cargo build
.
After that, you can use next commands.
- Parse a JSON file:
cargo run -- <file-path>
- To see usage of the program:
cargo run -- --help
- To see the credits:
cargo run -- --credits
- Author: Solovei Tymofii
- GitHub: @amitlos
- Version: 1.0