JSON 转 Python TypedDict
从 JSON 示例生成带类型注解的 Python TypedDict 类。
输入
结果
使用方法
Generate Python types
Paste a sample object and run Convert. The output imports typing helpers and defines a class per nested object.
- Paste a JSON object.
- Click Convert.
- Copy the Python code into your project.
Type mapping
Strings become str, integers int, decimals float, booleans bool, arrays List[T] and nested objects their own TypedDict class.
常见问题
Why TypedDict instead of dataclasses?
TypedDict describes plain dictionaries produced by json.loads without requiring conversion, which matches typical JSON handling.
How are null values typed?
They are typed as Any because null carries no type information.