brokenloop / jsontopydantic Goto Github PK
View Code? Open in Web Editor NEWWeb tool for generating Pydantic models from JSON objects
Home Page: https://jsontopydantic.com
License: MIT License
Web tool for generating Pydantic models from JSON objects
Home Page: https://jsontopydantic.com
License: MIT License
I tried loading large json(via webpage) with nested elements and seems it stuck "loading..." and doesn't output the pydantic class .
Json:
{"digital.ms.price.":{"popRelationship":null,"role":"Price","taxIncluded":"Included","priceCharacteristic":null,"recurringChargePeriodType":null,"description":{"en-US":"u 8GBprice"},"type":"TablePrice","recurringChargePeriodLength":null,"priceEvent":null,"priceRecord":[{"priority":0,"priceRecordId":"c9902af4-53ff-438e-aeb8-47c90c1381fc","price":[{"priceReduction":null,"id":"4093ddc4-7bd9-434f-996f-adf59f86d61b","validFor":{"endDateTime":null,"startDateTime":"2018-11-21T00:00:00Z"},"taxIncludedAmount":{"value":"26700.0","unit":"IDR"},"percentage":null,"dutyFreeAmount":null}],"parameter":{"SalesChannel":{"name":"SalesChannel","valueTo":null,"unitOfMeasure":null,"value":"Any_Value","valueFrom":null},"TIERED_PRICING_COUNTER":{"name":"TIERED_PRICING_COUNTER","valueTo":null,"unitOfMeasure":null,"value":"0","valueFrom":null}}},{"priority":0,"priceRecordId":"f177993b-2275-4d41-9f92-7a0aa453d12c","price":[{"priceReduction":null,"id":"046fca9e-dbdb-4480-8d7b-ea39473715af","validFor":{"endDateTime":null,"startDateTime":"2018-11-21T00:00:00Z"},"taxIncludedAmount":{"value":"26700.0","unit":"IDR"},"percentage":null,"dutyFreeAmount":null}],"parameter":{"SalesChannel":{"name":"SalesChannel","valueTo":null,"unitOfMeasure":null,"value":"Any_Value","valueFrom":null},"TIERED_PRICING_COUNTER":{"name":"TIERED_PRICING_COUNTER","valueTo":null,"unitOfMeasure":null,"value":"999","valueFrom":null}}}],"installments":null,"price":[],"priceCategory":null,"immediatePayOption":{"payOption":"Optional","payImmediately":null,"payAmount":null,"minPayAmount":null},"currency":"IDR","id":"00be0e7f-51d3-4793-bc9c-fbdf036dab85","overrideOption":[{"allowWaive":true,"extension":null,"userRole":null,"maxIncreaseValue":{"amount":{"value":"99999","unit":"IDR"},"taxIncludedAmount":null,"percentage":null,"dutyFreeAmount":null},"allowOverride":true,"maxDecreaseValue":{"amount":null,"taxIncludedAmount":null,"percentage":100,"dutyFreeAmount":null}}],"priceAlterationCategory":null,"key":{"sequence":"00be0e7f-51d3-4793-bc9c-fbdf036dab85","keyString":"2ed2f2a1-2e04-4870-bc4b-8479a7f87e7c_00be0e7f-51d3-4793-bc9c-fbdf036dab85","entityType":"2ed2f2a1-2e04-4870-bc4b-8479a7f87e7c","onlySequence":false},"policy":{"name":[{"locale":"en-US","value":"Tiered_pricing_policy_for_RC"}],"id":"ed536645-d038-4d55-a771-2e72b7e9789f"},"owner":"D1","unitOfMeasure":null,"validFor":{"endDateTime":null,"startDateTime":"2018-11-21T00:00:00Z"},"priceDifference":null,"priceType":"OC","isVersion":null,"effectivenessPolicy":null,"priceParameterAdditionalData":null,"keyPathMap":{"2ed2f2a1-2e04-4870-bc4b-8479a7f87e7c_00be0e7f-51d3-4793-bc9c-fbdf036dab85":""},"name":{"en-US":"23rad price"}}}
```
Hi! I think this project & website are great, but I wasn't able to use them because there's no license. I ended up using datamodel-code-generator directly, with some additional effort, since I wasn't sure what the terms of use were from outputs from your code or website. I would love to use this in the future!
When specify every field as Optional is checked only the top level fields are makred as optional, any nested classes are not marked as optional.
Input:
{
"foo": 5,
"barBaz": {
"nested":"hello"
}
}
Output
from __future__ import annotations
from typing import Optional
from pydantic import BaseModel
class BarBaz(BaseModel):
nested: str
class Model(BaseModel):
foo: Optional[int] = None
barBaz: Optional[BarBaz] = None
Thanks for the useful tool!
Example data is already being introduced on the base json provided. The fields could be used to provide an example to the pydantic field, which usually helps on the implementation.
I'm willing to contribute the change
Close this :)
Does this allow nested json?
Hi,
First of all, thanks for creating and deploying this project.
I'd like to contribute with a new feature to take advantage of Optional + snake_cased handling from datamodel-code-generator as I used it a lot locally, but I don't seem to have the right access to push anything to this repository.
Is there a specific setting that prevents me to do so ?
Hi! Thanks for the fantastic tool.
I created an implementation which does everything client-side. I think it works pretty well, and has privacy benefits. Just wanted to let you know in case you were interested in it.
The tool currently converts this json
{
"accounts": {
"98230": {
"name": "BHN1",
"status": "ACTIVE"
},
"57150": {
"name": "Sec",
"status": "ACTIVE"
}
}
}
to something along the lines of
class Accounts(BaseModel):
field_98230: Field98230 = Field(..., alias='98230')
field_57150: Field57150 = Field(..., alias='57150')
class Model(BaseModel):
accounts: Accounts
This might be more useful result rather than having a field for each value
class Model2(BaseModel):
accounts: Optional[OrderedDict[str, ModelItem]]
Python 3.8.8,
I'm trying to run the generator.py by itself and getting error:
root@a21f0d01a432:/webserver/myTest# python3 generator.py
Traceback (most recent call last):
File "gen.py", line 30, in <module>
result = translate(data)
File "gen.py", line 18, in translate
parser = JsonSchemaParser(
TypeError: __init__() got an unexpected keyword argument 'text'
can you tell what could be the reason?
If annotations
has been imported then dict
, list
, set
, tuple
will work instead of Dict
, List
, Set
, Tuple
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.