# JSON to Python

Generate Python classes from a JSON sample, either as Pydantic models or as standard library dataclasses. Nested objects become their own classes declared before they are used, optional and nullable fields use Optional with a None default where the key can be missing, and mixed values use Union. Field names become snake_case.

## Frequently asked questions

### How are nested objects named?

Every nested object becomes its own Python type, named after the key that holds it in PascalCase, so address becomes Address. Objects inside arrays take the singular of the array key, so users becomes User. Objects with exactly the same fields share one type.

### When is a field optional?

When an array holds several objects and a key is missing from some of them, that field is optional: its type is wrapped in Optional and it defaults to None. A key present in every sample is required. A single object has nothing to compare with, so all of its keys are required.

### How are null values handled?

A key that is null in some samples and has a value in others becomes Optional of the type. A key that is only ever null tells the tool nothing about its real type, so it becomes Optional[Any]; paste a sample with a real value to get a precise type.

### Which number types are used?

Whole numbers become int and numbers with a fraction become float. A field that holds both becomes float.

### What happens to keys that are not valid names?

Field names are converted to snake_case. Pydantic models keep the original key with Field(alias=...), so model_validate reads the JSON as it is. Dataclasses have no aliases, so rename the keys yourself before you build a dataclass from JSON whose keys are not valid Python names. Python keywords such as class get a trailing underscore.

### Is my JSON uploaded or stored?

The JSON is sent to the server only to generate the code for this request and is not stored. The generator only reads the structure and the value types of your sample, so you can replace sensitive values with placeholders of the same type before you paste it.

Your ad here?

[Email us](mailto:hi@dennn.is?subject=Advertising%20on%20OneClick%20Pro)

[Ad 433 tools for your AI agents through one MCP server.](https://multitaskai.com/?ref=oneclickpro)
