{"library":"genson","title":"GenSON","description":"GenSON is a powerful, user-friendly JSON Schema generator built in Python. Its core function is to take JSON objects and generate schemas that describe them, and it is unique in its ability to merge schemas. It was originally built to describe the common structure of a large number of JSON objects. The current version is 1.3.0, released on May 15, 2024, and the library is actively maintained.","status":"active","version":"1.3.0","language":"en","source_language":"en","source_url":"https://github.com/wolverdude/genson/","tags":["json","schema","json-schema","generator","validation","python"],"install":[{"cmd":"pip install genson","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"SchemaBuilder","correct":"from genson import SchemaBuilder"}],"quickstart":{"code":"from genson import SchemaBuilder\nimport json\n\n# Initialize SchemaBuilder\nbuilder = SchemaBuilder()\n\n# Add the first JSON object\nbuilder.add_object({\n    \"name\": \"Alice Johnson\",\n    \"email\": \"alice@example.com\",\n    \"age\": 30,\n    \"is_active\": True,\n    \"tags\": [\"user\", \"admin\"]\n})\n\n# Add a second JSON object, demonstrating schema merging\nbuilder.add_object({\n    \"name\": \"Bob Smith\",\n    \"email\": \"bob@example.com\",\n    \"age\": 25,\n    \"phone\": \"+1-555-0100\",\n    \"tags\": [\"user\"]\n})\n\n# Generate and print the unified JSON Schema\nschema = builder.to_schema()\nprint(json.dumps(schema, indent=2))","lang":"python","description":"This quickstart demonstrates how to initialize a `SchemaBuilder` and add multiple JSON objects to it. GenSON will automatically infer the common schema, merging types and determining required fields across all added objects. The resulting schema is then printed, prettified with an indent of 2."},"warnings":[{"fix":"Verify you are using the correct library for your needs. If working with Python JSON Schema generation, proceed. If porting Java Genson logic, look elsewhere.","message":"This `genson` library is *not* the Python equivalent of the Java 'Genson' library. If you are looking for Java's Genson features in Python, this is not the correct library. Consider Python's built-in `json` library for basic JSON handling.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Manually inspect and adjust the 'required' array in the generated schema if the default inference does not match your intended contract. For example, add `additionalProperties: false` manually if desired.","message":"GenSON infers types and marks *all observed fields as required* by default. If a field is present in some objects but not others, it will be made optional in the resulting schema. However, if a field is always present, it will be marked as 'required'.","severity":"gotcha","affected_versions":"All versions"},{"fix":"After generating the basic schema, manually add specific semantic constraints (e.g., `minLength`, `pattern`, `enum`, `description`) to fully describe your data model beyond its basic structure.","message":"GenSON only deals with a *subset of JSON Schema keywords* for inference (e.g., \"$schema\", \"type\", \"items\", \"properties\", \"patternProperties\", \"required\", \"anyOf\"). It does not automatically infer or include semantic constraints like `enum` values (unless seeded), `minLength`, `maxLength`, `pattern` for strings, or `minItems`, `maxItems` for arrays.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Familiarize yourself with Python's regex syntax for `patternProperties`. If using both `properties` and `patternProperties`, be mindful that existing explicit properties will take precedence during updates.","message":"GenSON uses Python's flavor of regular expressions for `patternProperties`. Be aware of potential differences if you are accustomed to other regex engines. Also, `genson` prefers `properties` over `patternProperties`: if a property already exists that matches one of your patterns, the normal property will be updated, not the pattern property.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-06T00:00:00.000Z","next_check":"2026-07-05T00:00:00.000Z"}