Need private packages and team management tools?Check out npm Teams »


0.2.0 • Public • Published


npm version Build Status codecov Known Vulnerabilities License Greenkeeper badge

Fuzzer for Joi

Warning this is a proof of concept and is currently a work in progress. It is mostly used by me to automatically add fuzzing to my hapi test suites so stability and accuracy though important is not a major factor.


const Joi  = require('joi');
const Juzz = require('juzz');
const schema = Joi.object({
        id: Joi.number().integer().min(1).max(1000).required(),
        name: Joi.string().alphanum().min(1).max(32).required(),
        blob: Joi.any()
const example = Juzz(schema);
const {errors} = schema.validate(example);
console.log(errors) // errors should not exist
console.log(example) // example will be some object that contains a valid


Juzz(schema, [options])

Generates a random example according to schema

schema - a valid joi schema

options - object with optional options

  • replace: (res, desc, rules) => new res - method that allows to override generated values default((res) => res)

    • res - the result that Juzz created
    • desc - the description for that item

    for example to replace all strings with 'aaaaa' use the following replace function -

    relace (res, desc, rules) {
        if (desc.type === 'string') {
            return 'aaaaa';
        return res;

    replace can also be useful when using custom version of joi without a standard types -

    relace (res, desc, rules) {
        if (desc.type === 'myCustomType') {
            return 'aaaaa';
        return res;
  • contextObject - should be identical to the context object passed to joi.validate when schema references a context default({})

  • strictBoolean - if set to true will bail with an error when schema description is not known (can be useful for debugging) default(false)

  • extendedTypesarray - custom types that will pass strict mode default([])

  • extendedTypesDictObject - Dictionary object to allow replacing custom type with built-in type for example: {customType: 'string'} default({})

  • stringMininteger: used if string min is not forced in schema default(0)

  • stringMaxinteger: used if string max is not forced in schema default(100)

  • numberMininteger: used if number min is not forced in schema default(-10e6)

  • numberMaxinteger: used if number max is not forced in schema default(10e6)

  • numberPrecisioninteger: used if number precision is not forced in schema default(4)

  • arrayMininteger: used if array min is not forced in schema default(0)

  • arrayMaxinteger: used if array max is not forced in schema default(10)

  • objectMininteger: used if object min is not forced in schema default(0)

  • objectMaxinteger: used if object max is not forced in schema _default(10)

Known issues

It is possible to have very limited schemas or even schemas which has no valid values. In cases where Juzz can not create a valid schema it might throw a value but can also return an undefined value or invalid value instead. If always getting a correct schema is essential, you should always check the returned value using joi validate method.

Schemas containing lazy values (Joi.lazy()) are currently not supported due to their description returned from joi is not useful. this will hopefully change in future versions.


npm i juzz

DownloadsWeekly Downloads






Unpacked Size

68.6 kB

Total Files


Last publish


  • avatar