2 releases
Uses new Rust 2024
| 0.1.1 | Oct 7, 2025 |
|---|---|
| 0.1.0 | Aug 10, 2025 |
#344 in Database interfaces
44KB
800 lines
random-json
A CLI tool to generate random data from a JSON schema to fill databases.
Overview
random-json is a command-line utility that generates realistic fake data based on JSON schemas. It's designed to help developers quickly populate databases with test data during development and testing phases.
See list of all the support data types here.
Installation
cargo install random-json
Options
-c, --count <COUNT> Number of times to repeat the JSON [default: 1]
-b, --before <BEFORE> String to print before every data generation of the JSON schema
-a, --after <AFTER> String to print after every data generation of the JSON schema
-f, --file <SCHEMA_FILE> Path to the json schema [default: schema.json]
-j, --json <JSON> Pass the JSON from stdout instead of via a json file. Overrides the --file option
-t, --type <DATA_TYPE> Generates some data of the given data type. Overrides the other options
-u, --user <USER_DEFINED> Add custom data types
-i, --interactive Select the data type with a dialog and fuzzy search. Overrides the other options
-l, --list List all available data types. Overrides the other options
-d, --debug Debug errors with more precise information
-h, --help Print help
Examples
# Generate data interactively
random-json --interactive
# Generate data from a specific schema
random-json --schema schema.json
# Generate multiple records that follow the json format.
random-json --count 1000
# List all options
random-json --help
Usage guide
See USAGE.md for more details on the schema and CLI syntax.
Prisma example
echo '{
"firstName": "FirstName",
"lastName": "LastName",
"phone_number": "PhoneNumber?",
"email": "Email"
}' >schema.json
random-json --count 2 --before "await prisma.person.create({ data: " --after " });
"
and the output will be
await prisma.person.create({ data: {
"firstName": "Eliane",
"lastName": "Perret",
"phone_number": "08 32 72 03 11",
"email": "stanislas_quia@free.fr"
} });
await prisma.person.create({ data: {
"firstName": "Herbert",
"lastName": "Salles",
"phone_number": "02 33 18 29 16",
"email": "pascal_amet@laposte.fr"
} });
[!TIP]
You can do this will any database/ORM, just customise the
--beforeand--afteroptions!
Supported Data Types
The tool supports a lots of data types through the random-data crate:
- Addresses: street, states, countries, coordinates, etc.
- Dates and times: timestamps, dates, etc.
- Internet: URLs, IP addresses, etc.
- Identifiers: UUIDs, ObjectIds, ULIDs, etc.
- Financial: currencies, decimal numbers, etc.
- Information: people names, emails, phone numbers, health insurance numbers, etc.
- Text: words, sentences, passwords, etc.
Use the random-json --list to list all supported data types.
Dependencies
clap: Command-line argument parsingserde_json: JSON serialization/deserializationrandom-data: Fake data generationdialoguer: Interactive command-line dialogue to select with fuzzy-finderrand: Random number generation (e.g. to choose when a nullable field becomes undefined)
Dependencies
~5.5–9MB
~170K SLoC