JSON to Pydantic

Turn JSON into Python Pydantic models, with nested objects, arrays and optional fields.

Pay by wallet (x402) json-to-pydantic

Example

Example answer
{
  "root_type": "Root",
  "model_count": 1,
  "pydantic_model": "from pydantic import BaseModel\nfrom typing import Any, List, Optional\n\nclass Root(BaseModel):\n    name: str\n    value: int"
}

Inputs

FieldTypeRequiredWhat it is
jsonanyYesJSON string or object
root_namestringNo—

Output fields

How reliably each field appears in a successful answer.

FieldTypeAppears
root_typestringAlways (present in every successful answer)
model_countintegerAlways (present in every successful answer)
pydantic_modelstringAlways (present in every successful answer)

How to call it

The same tool through each route. MCP clients reach it through Strale’s server at https://api.strale.io/mcp; the call below is what the agent sends.

# Needs an API key. max_price_cents caps what this call may cost.
curl -X POST https://api.strale.io/v1/do \
  -H "Authorization: Bearer $STRALE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "capability_slug": "json-to-pydantic",
    "inputs": {
      "json": "{\"name\": \"Test\", \"value\": 42}"
    },
    "max_price_cents": 5
  }'

Limitations

  • Optional fields can be inferred as required

    Infers Pydantic models from JSON samples — optional fields may be marked as required if always present in the sample

    What to do instead: Provide samples with null values for optional fields, or manually adjust Field(default=None) after generation