json-to-pydantic
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseJSON to Pydantic Skill
JSON 转 Pydantic 技能
This skill helps convert raw JSON data or API responses into structured, strongly-typed Python classes using Pydantic.
本技能可帮助你将原始JSON数据或API响应转换为结构化、强类型的Python类,使用Pydantic实现。
Instructions
操作步骤
-
Analyze the Input: Look at the JSON object provided by the user.
-
Infer Types:
- ->
stringstr - ->
numberorintfloat - ->
booleanbool - ->
arrayList[Type] - ->
nullOptional[Type] - Nested Objects -> Create a separate sub-class.
-
Follow the Example: Reviewto see how to structure the output code. notice how nested dictionaries like
examples/are extracted into their own class.preferences- Input:
examples/input_data.json - Output:
examples/output_model.py
- Input:
-
分析输入:查看用户提供的JSON对象。
-
推断类型:
- ->
stringstr - ->
number或intfloat - ->
booleanbool - ->
arrayList[Type] - ->
nullOptional[Type] - 嵌套对象 -> 创建独立的子类。
-
参考示例: 查看目录下的内容,了解如何构建输出代码。注意像
examples/这样的嵌套字典是如何提取为独立类的。preferences- 输入:
examples/input_data.json - 输出:
examples/output_model.py
- 输入:
Style Guidelines
风格指南
- Use for class names.
PascalCase - Use type hints (,
List) fromOptionalmodule.typing - If a field can be missing or null, default it to .
None
- 类名使用命名法。
PascalCase - 使用模块中的类型提示(
typing、List)。Optional - 如果某个字段可能缺失或为null,默认值设为。
None