Mockzilla logo

JSON Schema Reference

Mockzilla uses json-schema-faker (JSF) to generate dynamic, realistic data from your JSON Schemas. It provides a bridge between standard JSON Schema validation and data generation libraries like Faker.js.

Supported Specifications

Mockzilla currently uses json-schema-faker v0.5.9, which primarily supports JSON Schema Draft-04. Many common keywords from later drafts (like oneOf, anyOf, allOf) are also supported for generation.

Supported Keywords

JSF supports a wide range of standard JSON Schema keywords to guide data generation:

  • Logic: allOf, anyOf, oneOf, not (partially)
  • Objects: properties, required, additionalProperties, minProperties, maxProperties
  • Arrays: items (mandatory for validation), minItems, maxItems, uniqueItems
  • Strings: minLength, maxLength, pattern (RegExp), format, enum
  • Numbers: minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf
  • Metadata: default, examples, const

Faker.js Integration (v10)

Mockzilla integrates Faker.js v10 directly into the schema generation process. You can use the faker (or x-faker in OpenAPI) keyword on any schema property.

Passing Arguments to Faker

Modern Faker uses object notation for named parameters. This is the preferred syntax in Mockzilla.

{
  "faker": {
    "finance.amount": { "min": 100, "max": 1000, "dec": 2, "symbol": "$" }
  }
}

Common Faker Fields

CategoryMethod Examples
👤 PersonfullName, firstName, lastName, jobTitle
🌐 Internetemail, userName, password, url, ipv4
💰 Financeamount, accountNumber, currencyCode, iban
📍 LocationstreetAddress, city, zipCode, country
📅 Daterecent, future, past, birthdate
📦 Loremword, sentence, paragraph, slug
🔢 Systemstring.uuid, string.alphanumeric, number.int

High-Fidelity Patterns

Paginated List Response

{
  "type": "object",
  "properties": {
    "data": {
      "type": "array",
      "minItems": 5,
      "maxItems": 5,
      "items": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "faker": "string.uuid" },
          "title": { "type": "string", "faker": "lorem.sentence" }
        }
      }
    },
    "meta": {
      "type": "object",
      "properties": {
        "page": { "const": 1 },
        "total": { "type": "integer", "faker": { "number.int": { "min": 50, "max": 100 } } }
      }
    }
  }
}

Request Context & Interpolation

Mockzilla provides the request context to the schema generator, allowing you to reference request data directly in your schema.

Faker in Templates

You can call Faker methods directly within your templates using {{faker.method.submethod}}.

{
  "type": "object",
  "properties": {
    "randomEmail": { "type": "string", "const": "{{faker.internet.email}}" },
    "greeting": { "type": "string", "const": "Hello, {{faker.person.fullName}}!" }
  }
}

Referencing Path Captures and Query Parameters

Use double-brace interpolation in a string const to copy request values into a generated response. The first wildcard capture is $.params.[0]; query values use $.query.paramName. Query values are strings.

Interpolation copies a value into the response. It does not convert a query value to a number or use limit to resize an array; configure array length with minItems and maxItems. If a query key must exist, require it in Advanced Options → Query Parameters (for example, page = *).

{
  "type": "object",
  "properties": {
    "meta": {
      "type": "object",
      "properties": {
        "productId": { "type": "string", "const": "{{$.params.[0]}}" },
        "page": { "type": "string", "const": "{{$.query.page}}" },
        "limit": { "type": "string", "const": "{{$.query.limit}}" }
      }
    }
  }
}

For an end-to-end wildcard and query-parameter example, see Dynamic Wildcard Mocks.


Supported Formats

FormatGenerator
date-timeISO timestamp (built in)
dateISO date such as 1932-04-12 (built in)
emailRandom address (built in). Use "faker": "internet.email" for realistic names.
uuidUUID (built in)
passwordfaker.internet.password()
phonefaker.phone.number()
urifaker.internet.url()
hostnamefaker.internet.domainName()
ipv4 / ipv6faker.internet.ipv4() / faker.internet.ipv6()
country / country-codefaker.location.country() / faker.location.countryCode()
currency / currency-symbolfaker.finance.currencyCode() / faker.finance.currencySymbol()
credit-cardfaker.finance.creditCardNumber()
user-agent / mac / colorfaker.internet.userAgent() / faker.internet.mac() / faker.color.human()
byte / binary10 random alphanumeric characters

Faker date methods such as date.past return a JavaScript date string (Thu Nov 27 2025 09:22:33 GMT…). Add "format": "date-time" next to the faker keyword to get an ISO timestamp instead.


Best Practices

  • Mandatory items: For type: "array", an items subschema must be provided. Without it, generation fails and Mockzilla returns the mock's static response instead.
  • Always set maxItems: Arrays always generate exactly maxItems items. With no maxItems, an array generates MOCKZILLA_MAX_ITEMS (default 1000) items. For an empty array, set minItems and maxItems to 0.
  • Optional fields are generated: Every property in properties appears in the output, whether or not it is in required.
  • Explicit Types: Always specify a type for every property to ensure consistent generation.
  • OpenAPI import cap: OpenAPI import generates its static body with arrays capped at 3 items. The stored schema is not changed, so add maxItems before you switch an imported mock to Dynamic Response.
  • Faker arguments: Methods with arguments need object or array notation. "faker": "string.alphanumeric" returns a single character; use { "string.alphanumeric": 10 } for ten.