Crate jtd_fuzz[−][src]
Generate fuzzed data from a JSON Type Definition schema.
Quick start
Here's how you can use fuzz
to generate dummy data from a schema.
use serde_json::json; use rand::SeedableRng; // An example schema we can test against. let schema = jtd::Schema::from_serde_schema(serde_json::from_value(json!({ "properties": { "name": { "type": "string" }, "createdAt": { "type": "timestamp" }, "favoriteNumbers": { "elements": { "type": "uint8" } } } })).unwrap()).unwrap(); // A hard-coded RNG, so that the output is predictable. let mut rng = rand_pcg::Pcg32::seed_from_u64(8927); assert_eq!(jtd_fuzz::fuzz(&schema, &mut rng), json!({ "name": "f", "createdAt": "1931-10-18T16:37:09-03:03", "favoriteNumbers": [166, 142] }));
Functions
fuzz | Generates a single random JSON value satisfying a given schema. |