{"id":15659033,"url":"https://github.com/gowee/json2pyi","last_synced_at":"2025-08-27T13:22:56.276Z","repository":{"id":44896674,"uuid":"317459674","full_name":"Gowee/json2pyi","owner":"Gowee","description":"Generate Python type definitions from a JSON sample (both Pydantic BaseModel and TypedDict are supported)","archived":false,"fork":false,"pushed_at":"2025-01-16T03:08:17.000Z","size":4917,"stargazers_count":54,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-05T03:18:11.909Z","etag":null,"topics":["dataclass","json","mypy","pep589","pydantic","python","typeddict","web-app"],"latest_commit_sha":null,"homepage":"https://json2pyi.pages.dev","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gowee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-12-01T07:30:49.000Z","updated_at":"2025-04-30T03:54:39.000Z","dependencies_parsed_at":"2024-10-23T06:17:34.431Z","dependency_job_id":"e2db06e1-04c5-4bf7-9fd9-a9be40815f3e","html_url":"https://github.com/Gowee/json2pyi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Gowee/json2pyi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gowee%2Fjson2pyi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gowee%2Fjson2pyi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gowee%2Fjson2pyi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gowee%2Fjson2pyi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gowee","download_url":"https://codeload.github.com/Gowee/json2pyi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gowee%2Fjson2pyi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272335814,"owners_count":24916529,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-27T02:00:09.397Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dataclass","json","mypy","pep589","pydantic","python","typeddict","web-app"],"created_at":"2024-10-03T13:14:42.835Z","updated_at":"2025-08-27T13:22:56.250Z","avatar_url":"https://github.com/Gowee.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"![CI main workflow badge](https://github.com/Gowee/json2pyi/actions/workflows/main.yml/badge.svg)\n\n# JSON to Python Types\n\n*json2pyi* infers a type schema from a sample JSON file and generates Python type definitions ([`dataclass`](https://docs.python.org/3/library/dataclasses.html), Pydantic [`BaseModel`](https://pydantic-docs.helpmanual.io/usage/models/) or PEP-589 [`TypedDict`](https://www.python.org/dev/peps/pep-0589/)) accordingly. It runs in browser, requiring no installation.\n\n\u003c!--Even though the project is still an MVP, it is expected to be stable \u0026 usable as a Web app. Please do not hesitate to raise an issue if you find any problems.--\u003e\n\n__🌐 Available online 🔗__: \u003chttps://json2pyi.pages.dev\u003e\n\n## Example\n\n**Input:**\n\n```jsonc\n{\n    \"page\": {\n        \"id\": \"kctbh9vrtdwd\",\n        \"name\": \"GitHub\",\n        \"url\": \"https://www.githubstatus.com\",\n        \"time_zone\": \"Etc/UTC\",\n        \"updated_at\": \"2020-12-03T08:11:21.385Z\"\n    },\n    \"components\": [\n        {\n            \"id\": \"8l4ygp009s5s\",\n            \"name\": \"Git Operations\",\n            \"status\": \"operational\",\n            \"created_at\": \"2017-01-31T20:05:05.370Z\",\n            \"updated_at\": \"2020-10-29T22:51:43.831Z\",\n            \"position\": 1,\n            \"description\": \"Performance of git clones, pulls, pushes, and associated operations\",\n            \"showcase\": false,\n            \"start_date\": null,\n            \"group_id\": null,\n            \"page_id\": \"kctbh9vrtdwd\",\n            \"group\": false,\n            \"only_show_if_degraded\": false\n        },\n        /* ... */\n    ],\n    \"incidents\": [],\n    \"scheduled_maintenances\": [],\n    \"status\": {\n        \"indicator\": \"none\",\n        \"description\": \"All Systems Operational\"\n    }\n}\n```\n\n**Output:**\n\n```python\n@dataclass\nclass Page:\n    id = str\n    name = str\n    url = str\n    time_zone = str\n    updated_at = str\n\n@dataclass\nclass Components:\n    id = str\n    name = str\n    status = str\n    created_at = str\n    updated_at = str\n    position = int\n    description = Optional[str]\n    showcase = bool\n    start_date = None\n    group_id = None\n    page_id = str\n    group = bool\n    only_show_if_degraded = bool\n\n@dataclass\nclass Status:\n    indicator = str\n    description = str\n\n@dataclass\nclass RootObject:\n    page = Page\n    components = List[Components]\n    incidents = List[Any]\n    scheduled_maintenances = List[Any]\n    status = Status\n```\n\nOr:\n\n```python\nfrom typing import TypedDict, Optional, List\n\nfrom datetime import datetime\n\n\nIncidentUpdate = TypedDict(\"IncidentUpdate\", {\"body\": str, \"created_at\": datetime, \"display_at\": datetime, \"id\": str, \"incident_id\": str, \"status\": str, \"updated_at\": datetime})\n\nIncidentOrScheduledMaintenance = TypedDict(\"IncidentOrScheduledMaintenance\", {\"created_at\": datetime, \"id\": str, \"impact\": str, \"incident_updates\": List[IncidentUpdate], \"monitoring_at\": None, \"name\": str, \"page_id\": str, \"resolved_at\": None, \"shortlink\": str, \"status\": str, \"updated_at\": datetime, \"scheduled_for\": Optional[datetime], \"scheduled_until\": Optional[datetime]})\n\nComponent = TypedDict(\"Component\", {\"created_at\": datetime, \"description\": None, \"id\": str, \"name\": str, \"page_id\": str, \"position\": int, \"status\": str, \"updated_at\": datetime})\n\nStatus = TypedDict(\"Status\", {\"description\": str, \"indicator\": str})\n\nPage = TypedDict(\"Page\", {\"id\": str, \"name\": str, \"url\": str, \"updated_at\": datetime})\n\nRootObject = TypedDict(\"UnnammedType3C2BC8\", {\"page\": Page, \"status\": Status, \"components\": List[Component], \"incidents\": List[IncidentOrScheduledMaintenance], \"scheduled_maintenances\": List[IncidentOrScheduledMaintenance]})\n```\n\n## TODO\n\n- [ ] Detect tuple (array)\n- [x] Detect UUID / datetime\n- [ ] Detect Enum\n- [x] Merge data types with similar structure and common name prefix/suffix\n- [x] Detect recursive type definition (e.g. tree)\n- [x] Include imports of non-primitive types\n- [x] Generate type alias for complex Union\n- [ ] Improve the logic of determining whether a Union ix complex or not\n- [x] Generate TypedDict\n- [x] ~~Refactor to unify TypedDict and dataclass generation~~ Seperated intendedly for clear code structure.\n- [x] Compile to WASM and provide a Web-based app\n- [ ] Allow to tweak more options on Web app (partially blocked by \u003chttps://github.com/vhiribarren/raytracer-rust/issues/8\u003e)\n- [ ] Avoid merging data types with totally different structures in a union\n- [ ] Avoid unnecessary heap allocation by reducing one-time usage of Vec\n- [ ] Allow specifying the order of generated data types\n- [ ] Support more input types, such as JSON Schema\n- [ ] Support more target languages\n- [ ] Add usage instructions\n\n## Credits\n\nThe project is inspired by:\n\n- \u003chttps://app.quicktype.io/?l=ts\u003e\n- \u003chttps://github.com/thautwarm/schema-provider.py\u003e\n- \u003chttps://jvilk.com/MakeTypes/\u003e\n- \u003chttps://github.com/koxudaxi/datamodel-code-generator/\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgowee%2Fjson2pyi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgowee%2Fjson2pyi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgowee%2Fjson2pyi/lists"}