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.
pip install gensonVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.
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.
Run `pip install genson` in your terminal to install the library.
Implement a custom `SchemaStrategy` to handle `datetime` objects, typically by converting them to a string format and optionally adding a 'format': 'date-time' keyword to the schema.
Seed the `SchemaBuilder` with an initial schema that explicitly defines `anyOf` or ensures the merged types are handled correctly, or adjust the input data to allow for clearer type inference.
Upgrade GenSON to version 1.6 or higher if available (though the specified version is 1.3.0, the issue was identified as pre-1.6). If upgrading is not possible, implement depth limits or use an iterative parsing approach for deeply nested JSON data before feeding it to GenSON, or ensure inputs are not excessively nested.
No dependency data recorded yet.