JSON to Python
Generate TypedDict declarations with optional fields for sample responses.
Runs in your browser. Nothing is uploaded.
Infer Python TypedDicts from a JSON example
JSON to Python reads a representative JSON value and writes readable Python type declarations. Objects become TypedDict classes, nested objects receive PascalCase class names, and scalar values map to familiar Python annotations such as str, int,float, bool, and None. Arrays become list types, while mixed values are represented with a union. Paste JSON, use the sample, or drop a local file into the input area.
The generated module imports NotRequired for fields that are missing from some objects in an array. The All properties optional control applies the same marker to every field, which is useful when a sample is only a partial response. Empty arrays use list[Any] because there is no element evidence from which to infer a narrower type.
Read the output as an inference, not a contract
A JSON sample shows one set of values. It cannot tell the tool whether a string is an email, an identifier, a date, or a constrained set of allowed values. It also cannot prove that every future response has the same keys. Review the class names, rename them to match your domain, and add validation at the boundary where untrusted data enters your application. TypedDict improves editor and type-checker feedback, but it does not parse or validate runtime JSON by itself.
Arrays deserve special attention. A list of objects is merged by key so a field present in only some samples becomes optional. A list containing different scalar types becomes a union. A nullable value stays visible in the annotation. Compare several representative responses when an API has multiple shapes, then decide whether a single TypedDict or separate variants better describes the real protocol.
Practical Python cleanup
The output is intentionally small and dependency-free. It does not add a serialization framework, generate validators, or guess a web framework. Python version support matters because the generated union syntax uses the modern A | B form. If your project targets an older Python version, adjust the annotations or use the project's compatibility approach. Check field names when a JSON key contains punctuation because Python identifiers have stricter rules than JSON keys.
Use JSON Formatter to inspect and validate the source before inference. For another target language, compare JSON to TypeScript or JSON to Go. Downloading the result as types.py gives you a starting file that still deserves a code review before it enters a production package.
Private local inference
Parsing, inference, file reading, and downloading run in your browser. The JSON is not posted to a conversion service and TheDevTab never receives it. Treat the generated source as sensitive if the sample contains private field names or values, and remove those examples before sharing a fixture. The result is a description of the supplied sample, not a copy of its values, but the names can still reveal internal systems.
FAQ
Does JSON to Python send my sample to a conversion service?
JSON parsing and Python type inference happen in your browser, with no conversion request. The sample is never uploaded, and TheDevTab never receives it.
What does the tool generate?
Objects become TypedDict classes, nested objects become named classes, arrays become list types, and scalar values become annotations such as str, int, float, bool, and None. The output includes typing imports needed for TypedDict, Any, or NotRequired when those types occur.
How are optional fields represented?
A field missing from some objects in an array uses NotRequired in the generated TypedDict. The All properties optional option applies NotRequired to every inferred field.
What happens with an empty array?
An empty array becomes list[Any] because it contains no element from which to infer a narrower type. The output adds the Any import when that fallback is needed.
Does the output validate runtime JSON?
No. TypedDict declarations describe an expected shape for static type checkers, not runtime validation. Add parsing and validation at the boundary where your application receives JSON.
Can I use the generated union syntax everywhere?
The output writes unions with modern A | B syntax. If the project's Python version or typing conventions differ, adjust the declarations before using them.