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 Query Parameters

Access query parameters using the {$.query.paramName} syntax.

{
  "type": "object",
  "properties": {
    "meta": {
      "type": "object",
      "properties": {
        "page": { "const": "{$.query.page}" },
        "limit": { "const": "{$.query.limit}" }
      }
    }
  }
}

Supported Formats

FormatGenerator
passwordfaker.internet.password()
emailfaker.internet.email()
uuidfaker.string.uuid()
phonefaker.phone.number()
urifaker.internet.url()
ipv4 / ipv6IP Addresses

Best Practices

  • Mandatory items: For type: "array", an items subschema must be provided.
  • Explicit Types: Always specify a type for every property to ensure consistent generation.
  • Array Size Capped: By default, Mockzilla's OpenAPI import caps auto-generated arrays at maxItems: 3 for performance. You can manually increase this in the dashboard.