PyJSON → Python Converter
Loading...
Using API response JSON in a Python project requires writing dataclass or Pydantic models by hand. This tool analyzes your JSON data and generates the Python code automatically. It supports Pydantic v1/v2 and standard dataclasses, and automatically converts camelCase keys to snake_case field names.
How to Use
- 1Enter JSON
Paste JSON data into the left input. Click 'Load Example' to load sample data.
- 2Configure options
Choose the output mode (Pydantic v2 / Pydantic v1 / dataclass) and a root class name. Toggle Optional types and Field alias generation as needed.
- 3Copy the code
Review the generated Python code on the right and click the copy button to copy it to clipboard.
Tips
- 💡camelCase keys (e.g. userId) are automatically converted to snake_case (user_id). Enable 'Field alias' to preserve the original key name as an alias.
- 💡Pydantic v2 generates code for the latest Pydantic 2.x. Choose Pydantic v1 for older projects.
- 💡Type inference is based on the first object in each array, so use a representative JSON sample.
- 💡Enable 'Optional' to annotate null-valued fields as Optional[T].