noson
A Rust library that generates example JSON data from a JSON Schema.
Given a JSON Schema as a serde_json::Value, noson produces a random JSON
value that validates against it.
Usage
use SeedableRng;
use StdRng;
use json;
let schema = json!;
let mut rng = seed_from_u64;
let example = generate.unwrap;
// example is a random JSON value that validates against the schema
println!;
Supported Schema Features
- Types:
null,boolean,string,integer,number,object,array - Constraints:
minimum/maximum,exclusiveMinimum/exclusiveMaximum,minLength/maxLength,minItems/maxItems - Enum / Const:
enum,const - Composition:
allOf,anyOf,oneOf - References:
$refresolved against$defs/definitions - Boolean schemas:
true(any value) andfalse(error)
Not Supported
The following JSON Schema features are not currently handled. Schemas using
them will either be silently ignored (the keyword has no effect on generation)
or, in the case of external $ref, return an error.
- String:
pattern,format,contentEncoding,contentMediaType - Numeric:
multipleOf - Object:
additionalProperties,patternProperties,propertyNames,minProperties,maxProperties,unevaluatedProperties - Array:
prefixItems,additionalItems,contains,minContains,maxContains,uniqueItems,unevaluatedItems - Composition:
not,if/then/else - Dependencies:
dependentRequired,dependentSchemas - References: external
$ref(http/file URIs),$dynamicRef,$anchor - Type unions:
"type": ["string", "null"](array form oftype)
Roadmap
- Builder/configuration API -- customizable string length ranges, array sizes, max recursion depth
formatgenerators --date-time,email,uri,uuid, etc.patternsupport -- regex-based string generation viarand_regexadditionalPropertiesgenerationprefixItems,containsminProperties/maxPropertiesmultipleOfif/then/elsenotdependentRequired/dependentSchemas- External
$refresolution (http/file references)
Development
This project was developed with the assistance of LLMs (Claude).