| Crates.io | datafake-rs |
| lib.rs | datafake-rs |
| version | 0.2.2 |
| created_at | 2025-07-27 07:48:08.935959+00 |
| updated_at | 2026-01-10 10:15:39.28243+00 |
| description | High-performance JSON mock data generation using JSONLogic configuration |
| homepage | https://github.com/GoPlasmatic/datafake-rs |
| repository | https://github.com/GoPlasmatic/datafake-rs |
| max_upload_size | |
| id | 1769807 |
| size | 215,897 |
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.
datalogic-rs for efficient evaluation.You define your data schema using a JSONLogic configuration with custom operators.
use datafake_rs::DataGenerator;
use serde_json::json;
let config = json!({
"variables": {
"userId": {"fake": ["uuid"]},
"country": {"fake": ["country_code"]}
},
"schema": {
"id": {"var": "userId"},
"profile": {
"name": {"fake": ["name"]},
"email": {"fake": ["email"]},
"age": {"fake": ["u8", 18, 65]}
},
"location": {
"country": {"var": "country"},
"city": {"fake": ["city_name"]},
"coordinates": {
"lat": {"fake": ["latitude"]},
"lng": {"fake": ["longitude"]}
}
}
}
});
let generator = DataGenerator::from_value(config)?;
let mock_data = generator.generate()?;
The library integrates with datalogic-rs and adds a fake operator, while still supporting all standard JSONLogic operators.
{
"schema": {
"active": {"==": [{"var": "status"}, "active"]},
"discount": {"if": [
{">": [{"var": "age"}, 65]},
0.2,
0.0
]},
"code": {"fake": ["u32", 1000, 9999]}
}
}
The fake operator can generate over 50 different types of data.
{"fake": ["u8"]}
{"fake": ["u16", 100, 1000]}
{"fake": ["i32", -50, 50]}
{"fake": ["f64", 0.0, 1.0]}
{"fake": ["name"]}
{"fake": ["first_name"]}
{"fake": ["last_name"]}
{"fake": ["title"]}
{"fake": ["email"]}
{"fake": ["phone_number"]}
{"fake": ["street_address"]}
{"fake": ["city_name"]}
{"fake": ["state_name"]}
{"fake": ["country_name"]}
{"fake": ["zip_code"]}
{"fake": ["latitude"]}
{"fake": ["longitude"]}
{"fake": ["bic"]} // Random 8 or 11 character BIC
{"fake": ["bic", 8]} // Fixed 8 character BIC
{"fake": ["bic", 11]} // Fixed 11 character BIC
{"fake": ["bic8"]} // Fixed 8 character BIC (shorthand)
{"fake": ["bic11"]} // Fixed 11 character BIC (shorthand)
{"fake": ["credit_card_number"]}
{"fake": ["currency_code"]}
{"fake": ["currency_symbol"]}
{"fake": ["username"]}
{"fake": ["password", 10, 20]}
{"fake": ["ipv4"]}
{"fake": ["ipv6"]}
{"fake": ["mac_address"]}
{"fake": ["user_agent"]}
{"fake": ["domain_suffix"]}
{"fake": ["company_name"]}
{"fake": ["industry"]}
{"fake": ["profession"]}
{"fake": ["catch_phrase"]}
{"fake": ["word"]}
{"fake": ["words", 5]}
{"fake": ["sentence", 5, 10]}
{"fake": ["paragraph", 3, 5]}
{"fake": ["uuid"]}
You can pre-generate values and reuse them in your schema.
{
"variables": {
"sessionId": {"fake": ["uuid"]},
"timestamp": {"fake": ["u64", 1600000000, 1700000000]},
"userId": {"fake": ["u32", 1000, 9999]}
},
"schema": {
"session": {"var": "sessionId"},
"events": [
{
"id": {"fake": ["uuid"]},
"session": {"var": "sessionId"},
"user": {"var": "userId"},
"timestamp": {"var": "timestamp"},
"action": {"fake": ["word"]}
}
]
}
}
Add datafake-rs to your Cargo.toml:
[dependencies]
datafake-rs = "0.1.0"
Or use cargo:
cargo add datafake-rs
use datafake_rs::DataGenerator;
let config = r#"{
"schema": {
"id": {"fake": ["uuid"]},
"name": {"fake": ["name"]},
"email": {"fake": ["email"]},
"age": {"fake": ["u8", 18, 65]},
"active": {"fake": ["bool"]}
}
}"#;
let generator = DataGenerator::from_json(config)?;
let mock_user = generator.generate()?;
println!("{}", serde_json::to_string_pretty(&mock_user)?);
use datafake_rs::DataGenerator;
use serde_json::json;
let config = json!({
"variables": {
"companyId": {"fake": ["uuid"]},
"createdAt": {"fake": ["u64", 1600000000, 1700000000]}
},
"schema": {
"company": {
"id": {"var": "companyId"},
"name": {"fake": ["company_name"]},
"employees": [
{
"id": {"fake": ["uuid"]},
"name": {"fake": ["name"]},
"email": {"fake": ["email"]}
}
]
}
}
});
let generator = DataGenerator::from_value(config)?;
let company_data = generator.generate()?;
Generate a list of unique records.
let config = json!({
"schema": {
"id": {"fake": ["uuid"]},
"transaction": {
"amount": {"fake": ["f64", 10.0, 1000.0]},
"currency": {"fake": ["currency_code"]}
}
}
});
let generator = DataGenerator::from_value(config)?;
let transactions = generator.generate_batch(100)?;
Use JSONLogic conditions to shape your data.
let config = json!({
"variables": {
"age": {"fake": ["u8", 10, 80]}
},
"schema": {
"age": {"var": "age"},
"ageGroup": {
"if": [
{"<": [{"var": "age"}, 18]}, "minor",
{"<": [{"var": "age"}, 65]}, "adult",
"senior"
]
}
}
});
To run the test suite:
# Run all tests
cargo test
# Run a specific test with output
cargo test test_generate_batch -- --nocapture
Contributions are welcome! If you're submitting a change, please ensure it has good test coverage and documentation.
datafake-rs is an open-source project from Plasmatic. We build developer tools that are performant and based on open standards.
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
Built with โค๏ธ by the Plasmatic team