mirror of
https://github.com/koxudaxi/datamodel-code-generator.git
synced 2024-03-18 14:54:37 +03:00
* Make small grammatical and phrasing changes, update external like to JSON schema docs, remove unused schema keywords, unify JSON Schema language * Title case some headers, modify some phrasing, remove duplicate custom template docs, clean up using_as_module with phrasing and removal of redundant ending. * Add crosslinks between documents for clarity, rephrase sectinos, unify representation of "JSON Schema", remove specifictation of temporary directory use * Reword "File" to "Data" to include python dicts, update working on project mentions * Update language from "repositories" to "projects" to include links that are not repos * Small phrasing update * Update phrasing of supported data page for clairty * Unify representation of "JSON", remove redundant information from index * Synchronize changes between readme and index page * Standardize formatting, fix heading levels
1.0 KiB
1.0 KiB
Generate from JSON Data
This code generator can create pydantic models from JSON Data. Under the hood, the generator uses GenSON to create JSON Schema from your input. The generated schema is then processed the in the same manner as JSON Schema input data.
Example
$ datamodel-codegen --input pets.json --input-file-type json --output model.py
pets.json
{
"pets": [
{
"name": "dog",
"age": 2
},
{
"name": "cat",
"age": 1
},
{
"name": "snake",
"age": 3,
"nickname": "python"
}
],
"status": 200
}
model.py
# generated by datamodel-codegen:
# filename: pets.json
# timestamp: 2020-04-27T16:08:21+00:00
from __future__ import annotations
from typing import List, Optional
from pydantic import BaseModel
class Pet(BaseModel):
name: str
age: int
nickname: Optional[str] = None
class Model(BaseModel):
pets: List[Pet]
status: int