Docs
datagen-rs

datagen-rs

A Rust library for generating random data from a JSON schema.

Installation

Add the following to your Cargo.toml:

[dependencies]
datagen-rs = "0.1.0"

Usage

Generate data from a schema file

use datagen_rs::util::helpers::{generate_random_data, read_schema};
 
fn main() {
    let schema = read_schema("path/to/schema.json").unwrap();
    let data = generate_random_data(schema, None).unwrap();
    println!("{}", data);
}

Generate data from a schema string

use datagen_rs::util::helpers::{generate_random_data_from_str, read_schema};
 
fn main() {
    let schema: Schema = serde_json::from_str(r#"
    {
        "type": "string",
        "value": "test
    }
    "#).unwrap();
    let data = generate_random_data_from_str(&schema, None).unwrap();
    println!("{}", data);
}

Write the JSON schema to a file

use datagen_rs::util::helpers::write_json_schema;
 
fn main() {
    write_json_schema("path/to/schema.json").unwrap();
}

Features

FeatureDescriptionDepends on
pluginEnables loading plugins
native-pluginEnables loading plugins written in Rustplugin
serializeEnables serialization/deserialization for all structs using serde.
map-schemaEnables data generation for several typesserialize
generateEnables data generation for all typesmap-schema
schemaEnables JSON schema generation using schemarsserialize
allEnables all featuresnative-plugin, generate, schema