| Crates.io | jtd-fuzz |
| lib.rs | jtd-fuzz |
| version | 0.2.0 |
| created_at | 2020-04-26 20:47:16.326966+00 |
| updated_at | 2021-02-04 21:13:28.432526+00 |
| description | Generates example data from JSON Typedef schemas |
| homepage | |
| repository | |
| max_upload_size | |
| id | 234431 |
| size | 50,137 |
jtd-fuzz generates example data (aka "fuzz tests") from a JSON Typedef
schema.
echo '{ "elements": { "type": "string" }}' | jtd-fuzz -n 5
["_","/+Z`","8o~5[7A"]
[]
["@(;","*+!YVz"]
["u4sv>Sp","Uc","o`"]
["","G","*ZJsc","","","\"RT,","l>l"]
On macOS, you can install jtd-fuzz via Homebrew:
brew install jsontypedef/jsontypedef/jtd-fuzz
For all other platforms, you can download and extract the binary yoursel from
the latest release. You can also install using cargo by running:
cargo install jtd_fuzz
To invoke jtd-fuzz, you can either:
jtd-fuzz.jtd-fuzz reads in a single JSON Typedef schema, and will output, by default,
an infinite stream of examples. For example, this will output an infinite
sequence of random JSON data:
echo '{}' | jtd-fuzz
If you'd like to have jtd-fuzz output an exact number of results, use -n:
echo '{}' | jtd-fuzz -n 5
Or, to have jtd-fuzz read from a file:
echo '{ "type": "timestamp" }' > foo.jtd.json
jtd-fuzz -n 5 foo.jtd.json
fuzzHintOftentimes, it's useful for jtd-fuzz to generate specific sorts of strings,
instead of the generic nonsense strings you get by default with {"type": "string"}. You can customize jtd-fuzz's output using the fuzzHint metadata
property. For example, this schema:
{
"metadata": {
"fuzzHint": "en_us/internet/email"
},
"type": "string"
}
Would, if you put it in a file called example.jtd.json, generate data like
this:
jtd-fuzz -n 5 example.jtd.json
"nerdman9@bergnaum.name"
"christopkulas@crooks.biz"
"ykozey5@wiza.org"
"rowenakunde@lang.com"
"udouglas01@carter.info"
fuzzHint will only work on schemas of {"type": "string"}. Here are some
commonly-used values for fuzzHint:
en_us/company/company_name generates strings like Hayes, Murray, and Kiehnen_us/internet/email generates strings like alainatorphy@johnson.comen_us/names/full_name generates strings like Alexa WisozkA full list of possible values for fuzzHint is available
here.
By default, jtd-fuzz will generate different output every time:
echo '{}' | jtd-fuzz -n 1 ; echo '{}' | jtd-fuzz -n 1
{"[jD|6W":null}
null
If you'd like to get consistent output from jtd-fuzz, or be able to reproduce
its output, you can use the -s option to provide a seed to its internal
pseudo-random number generator. For the same seed and schema, jtd-fuzz will
output the same data every time:
echo '{}' | jtd-fuzz -n 1 -s 8927 ; echo '{}' | jtd-fuzz -n 1 -s 8927
48
48
The -s option takes an integer between 0 and 2^64 - 1.
Seeding jtd-fuzz can be useful if you're using jtd-fuzz to do automated
testing against a system. Your automated testing system can pass jtd-fuzz a
randomly-generated seed, and if the automated tester finds a seed that reveals a
bug, it can output the seed it used. That way, developers can re-use that seed,
and try to reproduce the issue locally.
Note that jtd-fuzz is only guaranteed to produce consistent output if you use
the same seed, schema, and version of jtd-fuzz. Different versions on
jtd-fuzz may output different results, even if you give them the same seed and
schema.
Do not rely on jtd-fuzz as a source of cryptographically secure randomness.
jtd-fuzz is meant to be used as a generator of example data, such as for fuzz
testing applications. It is not meant to be used for cryptographic purposes.