datafake-rs
A high-performance mock JSON data generation library for Rust.
Uses JSONLogic for flexible and powerful fake data generation.
datafake-rs
is a Rust library for generating realistic mock JSON data. It uses JSONLogic for its configuration, allowing you to define complex data structures with ease. The library extends JSONLogic with a custom fake
operator, powered by the fake-rs
crate, to generate a wide variety of data types for testing, development, and other use cases.
๐ Key Features
- JSONLogic Based: Define data generation rules using JSONLogic expressions.
- Rich Fake Data: Over 50 fake data types, including names, addresses, and financial data.
- Variable System: Pre-generate and reuse values throughout your schema.
- Type-Safe: Ensures strong typing with thorough validation.
- Batch Generation: Easily create multiple, unique data records.
- High Performance: Built on
datalogic-rs
for efficient evaluation. - Flexible Configuration: Use JSON for easy setup and integration.
- Thread-Safe: Designed for safe concurrent data generation.
๐๏ธ How It Works
Configuration-Driven Design
You define your data schema using a JSONLogic configuration with custom operators.
use DataGenerator;
use json;
let config = json!;
let generator = from_value?;
let mock_data = generator.generate?;
JSONLogic Integration
The library integrates with datalogic-rs
and adds a fake
operator, while still supporting all standard JSONLogic operators.
๐ฏ Fake Data Generation
Supported Data Types
The fake
operator can generate over 50 different types of data.
Numeric
Personal
Address
Financial
Internet
Company
Content
Variable System
You can pre-generate values and reuse them in your schema.
๐ง Installation
Add datafake-rs
to your Cargo.toml
:
[]
= "0.1.0"
Or use cargo
:
๐ Usage Examples
Basic Example
use DataGenerator;
let config = r#"{
"schema": {
"id": {"fake": ["uuid"]},
"name": {"fake": ["name"]},
"email": {"fake": ["email"]},
"age": {"fake": ["u8", 18, 65]},
"active": {"fake": ["bool"]}
}
}"#;
let generator = from_json?;
let mock_user = generator.generate?;
println!;
Nested Structures
use DataGenerator;
use json;
let config = json!;
let generator = from_value?;
let company_data = generator.generate?;
Batch Generation
Generate a list of unique records.
let config = json!;
let generator = from_value?;
let transactions = generator.generate_batch?;
Conditional Logic
Use JSONLogic conditions to shape your data.
let config = json!;
๐งช Testing
To run the test suite:
# Run all tests
# Run a specific test with output
๐ค Contributing
Contributions are welcome! If you're submitting a change, please ensure it has good test coverage and documentation.
๐ข About Plasmatic
datafake-rs
is an open-source project from Plasmatic. We build developer tools that are performant and based on open standards.
๐ License
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
๐ See Also
- datalogic-rs: A high-performance JSONLogic implementation for Rust.
- fake-rs: A library for generating fake data in Rust.
- JSONLogic: The official JSONLogic specification.