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.
pip install jsfVerified import paths — ran on the pinned version, not inferred.
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.
Ensure Pydantic is installed at version 2.x (`pip install 'pydantic>=2.0'`). If incompatible with other project dependencies, consider pinning `jsf` to `<0.8.0`.
Be aware of the `prefer_default` and `prefer_examples` parameters when calling `jsf.resolve()` or `JSF.generate()`. If you want purely random data even when defaults/examples are present, ensure these parameters are set to `False` (their default is `False` but custom usage might enable them).
For versions 0.10.0 and above, use the `force_non_required_fields=True` parameter in `jsf.resolve()` or `JSF.generate()` if you always want non-required fields to be present. If you prefer sparse data, ensure this parameter is `False`.
If your schemas involve recursive definitions or complex enum structures with objects, ensure you are using `jsf` version 0.11.0 or newer to benefit from these fixes.