JGD-rs CLI - Command Line Tool for JSON Generation
A command-line interface for generating JSON data from JGD (JSON Generator Definition) schema files.
Overview
The JGD-rs CLI tool allows you to generate realistic JSON data from declarative schema definitions directly from the command line. It's built on top of the jgd-rs library and provides a simple interface for batch JSON generation, testing, and data seeding.
Installation
From Source
Clone the repository and build the CLI tool:
The binary will be available at ./target/release/jgd-rs-cli.
Using Cargo
Usage
Arguments
<INPUT>- Path to the .jgd schema file
Options
-o, --out <FILE>- Output file (JSON). If omitted, prints to stdout--seed <SEED>- Seed override for deterministic generation-p, --pretty- Pretty print the JSON output-h, --help- Print help information-V, --version- Print version information
Examples
Basic Usage
Generate JSON data and print to stdout:
Output to File
Generate JSON data and save to a file:
Pretty Print Output
Generate formatted JSON with proper indentation:
Using Custom Seed
Generate deterministic data with a specific seed:
Complete Example
This command:
- Uses the
user-post-entities.jgdschema file - Sets seed to 12345 for reproducible output
- Formats the JSON with pretty printing
- Saves the result to
generated-data.json
Sample Schema Files
The repository includes several example schema files you can use:
# Generate a single user object
# Generate an array of objects
# Generate complex multi-entity data
Sample Output
Input Schema (user.jgd)
Command
Output
Use Cases
1. API Testing
Generate test data for API endpoints:
# Generate user test data
# Generate product catalog
2. Database Seeding
Create seed data for development databases:
# Generate 1000 users with relationships
3. Mock Data Generation
Create realistic mock data for frontend development:
# Generate blog posts with authors
4. Data Pipeline Testing
Generate consistent test data for data processing pipelines:
# Generate reproducible test data
Integration with Build Tools
Makefile Integration
: :
: :
npm/package.json Scripts
Docker Integration
FROM rust:1.70 as builder
COPY . /app
WORKDIR /app
RUN cargo build --release
FROM debian:bullseye-slim
COPY --from=builder /app/target/release/jgd-rs-cli /usr/local/bin/
COPY schemas/ /schemas/
CMD ["jgd-rs-cli", "/schemas/default.jgd", "--pretty"]
Performance Considerations
- Large Datasets: For generating large amounts of data, consider using range counts in your schemas rather than fixed large numbers
- Memory Usage: The tool loads the entire generated dataset into memory before output
- Deterministic Generation: Using seeds ensures reproducible output but may be slightly slower than random generation
- File I/O: Writing to files is generally faster than stdout for large datasets
Troubleshooting
Common Issues
Invalid Schema Format
Solution: Ensure your schema follows the JGD format. See the schema documentation.
File Not Found
Solution: Check that the input file path is correct and the file exists.
Permission Denied
)
Solution: Ensure you have read permissions for the input file and write permissions for the output directory.
Debug Mode
For troubleshooting, you can use Rust's built-in logging:
RUST_LOG=debug
Schema Validation
The CLI tool automatically validates input schemas against the JGD specification. For additional validation, you can use external JSON Schema validators with the JGD schema definition.
Exit Codes
0- Success1- Error (invalid schema, file not found, etc.)
Related Documentation
- JGD Library Documentation - Complete API reference and schema documentation
- JSON Schema Definition - Formal schema specification
- Example Schemas - Sample JGD files to get started
Contributing
Contributions are welcome! To contribute to the CLI tool:
- Fork the repository
- Create a feature branch
- Make your changes to the CLI code
- Add tests if applicable
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.