{"id":4590,"library":"jsf","title":"jsf: Fake JSON from Schema","description":"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.","status":"active","version":"0.11.2","language":"en","source_language":"en","source_url":"https://github.com/ghandic/jsf","tags":["json","schema","fake-data","testing","development","data-generation"],"install":[{"cmd":"pip install jsf","lang":"bash","label":"Install latest stable version"}],"dependencies":[{"reason":"Used for internal schema parsing and validation. Version 2.x is required since jsf 0.8.0.","package":"pydantic","optional":false}],"imports":[{"note":"The `resolve` function is a top-level convenience function for generating a single JSON object.","symbol":"resolve","correct":"import jsf\nresult = jsf.resolve(schema)"},{"note":"The `JSF` class allows for more control, such as generating multiple instances from the same schema or custom configurations.","symbol":"JSF","correct":"from jsf import JSF\ngenerator = JSF(schema)\nresult = generator.generate()"}],"quickstart":{"code":"import jsf\nimport os\n\n# Example JSON schema\nschema = {\n    \"type\": \"object\",\n    \"properties\": {\n        \"id\": {\"type\": \"string\", \"format\": \"uuid\"},\n        \"name\": {\"type\": \"string\", \"pattern\": \"^[A-Za-z ]+$\"},\n        \"age\": {\"type\": \"integer\", \"minimum\": 18, \"maximum\": 99},\n        \"email\": {\"type\": \"string\", \"format\": \"email\"},\n        \"isActive\": {\"type\": \"boolean\"},\n        \"tags\": {\"type\": \"array\", \"items\": {\"type\": \"string\"}, \"minItems\": 1, \"maxItems\": 3}\n    },\n    \"required\": [\"id\", \"name\", \"age\", \"email\", \"isActive\"]\n}\n\n# Generate a single fake JSON object\nfake_data = jsf.resolve(schema)\nprint(fake_data)\n\n# To demonstrate with a custom generator for multiple items or specific options\n# from jsf import JSF\n# generator = JSF(schema)\n# print(generator.generate(prefer_default=True)) # Example of using a generator with options","lang":"python","description":"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."},"warnings":[{"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`.","message":"Version 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.","severity":"breaking","affected_versions":">=0.8.0"},{"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).","message":"Starting 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.","severity":"gotcha","affected_versions":">=0.11.2"},{"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`.","message":"Prior 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.","severity":"gotcha","affected_versions":"<0.10.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.","message":"In 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.","severity":"gotcha","affected_versions":"<0.11.0"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}