mcpField
J
json-to-pydantic

json-to-pydantic

github.com/rominiraniDevelopment60750 installsUpdated 18w ago
Repository

About json-to-pydantic

json-to-pydantic is a skill that turns JSON data or API responses into typed Python classes with Pydantic. It infers field types and extracts nested objects into separate classes.

Key features

  1. 01Infers Python types from JSON
  2. 02Creates classes for nested objects
  3. 03Uses PascalCase class names
  4. 04Makes nullable or missing fields default to None

Use cases

  1. 01Model an API response in Python
  2. 02Convert nested JSON into typed classes
  3. 03Generate a Pydantic model from sample data

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/rominirani/antigravity-skills --skill json-to-pydantic

After installing, type/json-to-pydanticin Claude Code to confirm it loaded.

Bundled filesexamples/input_data.jsonexamples/output_model.py

Details

From the project README

JSON to Pydantic Skill

This skill helps convert raw JSON data or API responses into structured, strongly-typed Python classes using Pydantic.

Instructions

  1. Analyze the Input: Look at the JSON object provided by the user.

  2. Infer Types:

    • string -> str
    • number -> int or float
    • boolean -> bool
    • array -> List[Type]
    • null -> Optional[Type]
    • Nested Objects -> Create a separate sub-class.
  3. Follow the Example: Review examples/ to see how to structure the output code. notice how nested dictionaries like preferences are extracted into their own class.

    • Input: examples/input_data.json
    • Output: examples/output_model.py

Style Guidelines

  • Use PascalCase for class names.
  • Use type hints (List, Optional) from typing module.
  • If a field can be missing or null, default it to None.

Comments

Markdown supported