2 releases
0.1.1 | Sep 21, 2024 |
---|---|
0.1.0 | Sep 21, 2024 |
#1078 in Development tools
15KB
304 lines
JSON Schema Generator
This is a command-line tool that generates JSON Schema from JSON data. It's built in Rust and provides a simple way to create JSON Schema definitions from existing JSON structures.
Features
- Generate JSON Schema from JSON files or stdin
- Support for all JSON data types (object, array, string, number, boolean, null)
- Automatic detection of required fields
- Handling of mixed-type arrays
- Output to file or stdout
Installation
To install the JSON Schema Generator, you need to have Rust and Cargo installed on your system. Then, you can clone this repository and build the project:
Use directly as a Cargo utility
cargo install json_schema_generator
json_schema_generator test.json
Build from Source
git clone https://github.com/AtlasPilotPuppy/json-schema-generator.git
cd json-schema-generator
cargo build --release
The compiled binary will be available in target/release/json_schema_generator
.
Usage
json_schema_generator [OPTIONS] [INPUT_FILE]
Options:
-o, --output <FILE>
: Specify the output file. If not provided, output will be written to<INPUT_FILE>.jsonschema
or stdout if reading from stdin.-s, --stdout
: Force output to stdout, even when an input file is provided.-h, --help
: Print help information.
Examples:
-
Generate schema from a file:
json_schema_generator input.json
-
Generate schema from a file and save to a specific output file:
json_schema_generator input.json -o output_schema.json
-
Generate schema from stdin:
cat input.json | json_schema_generator
-
Generate schema from a file and output to stdout:
json_schema_generator input.json --stdout
JSON Schema Version
This tool generates JSON Schema compatible with draft-07.
Limitations
- The tool generates a basic schema and may not capture all possible constraints or patterns in your data.
- The schema for arrays assumes all items in the array follow the same schema.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Dependencies
~2.1–3MB
~59K SLoC