jsf: Fake JSON from Schema

0.11.2 · active · verified Sun Apr 12

JSF (JSON Schema Faker) is a Python library designed to generate realistic-looking fake JSON data based on a given JSON schema. It supports a wide range of JSON schema features, including types, formats, patterns, and more complex structures like arrays and objects. The library is actively maintained with frequent releases, with the current stable PyPI version being 0.11.2, although more recent releases like 0.11.4 have appeared on GitHub, indicating a rapid development pace.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `jsf.resolve()` to generate a single fake JSON object based on a provided JSON schema. It showcases various schema properties like types, formats, patterns, minimum/maximum values, and required fields. For more advanced use cases, such as generating multiple items or applying specific options (e.g., preferring default values), the `JSF` class can be instantiated directly.

import jsf
import os

# Example JSON schema
schema = {
    "type": "object",
    "properties": {
        "id": {"type": "string", "format": "uuid"},
        "name": {"type": "string", "pattern": "^[A-Za-z ]+$"},
        "age": {"type": "integer", "minimum": 18, "maximum": 99},
        "email": {"type": "string", "format": "email"},
        "isActive": {"type": "boolean"},
        "tags": {"type": "array", "items": {"type": "string"}, "minItems": 1, "maxItems": 3}
    },
    "required": ["id", "name", "age", "email", "isActive"]
}

# Generate a single fake JSON object
fake_data = jsf.resolve(schema)
print(fake_data)

# To demonstrate with a custom generator for multiple items or specific options
# from jsf import JSF
# generator = JSF(schema)
# print(generator.generate(prefer_default=True)) # Example of using a generator with options

view raw JSON →