Registry / serialization / jsf
library0.11.2pypypi✓ verified 21d ago

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 jsf
INSTALL
IMPORT
SIG · JSF
J
jsf
serializationpythonv0.11.2
Install
6.7s avg
Import
1351ms
Disk
59MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.11.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.394s · 61.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 6.7s · import 1.308s · 61MB
59MB installed
● package 59MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JSF
from jsf import JSF
import jsf
parser
from jsf import parser
schema_types
from jsf import schema_types

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
jsf --version
Debug
Known issues
breakingVersion 0.8.0 introduced a breaking change by switching its internal dependency to Pydantic v2. Projects using Pydantic v1.x alongside `jsf` will need to upgrade Pydantic to v2.x or pin `jsf` to a version prior to 0.8.0.
fix
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`.
affects: >=0.8.0
gotchaStarting from version 0.11.2, `jsf` supports options to `prefer_default` and `prefer_examples` during generation. If your schema includes `default` or `examples` keywords and you were previously relying on random generation for these fields, your generated data might change if these new options are enabled, potentially leading to less varied data.
fix
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).
affects: >=0.11.2
gotchaPrior to version 0.10.0, non-required fields in a schema might not have been generated by default. Version 0.10.0 introduced the `force_non_required_fields` option, which, when enabled, ensures that even optional fields are always generated. Users upgrading might notice a change in data sparsity if they expected optional fields to sometimes be omitted.
fix
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`.
affects: <0.10.0
gotchaIn versions prior to 0.11.0, `jsf` had limited support for recursive schemas and enums of objects, which could lead to errors or incorrect generation. These issues were addressed in version 0.11.0.
fix
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.
affects: <0.11.0
Upgrade
Version history
0.11.2latest on PyPI · released Mar 26, 2024
Audit
Dependencies
pydanticrequiredUsed for internal schema parsing and validation. Version 2.x is required since jsf 0.8.0.
Agent activity
7 hits · last 30 days
node
6
Resources
jsf — pip install jsf · libregistry