Skip to content

Converts a stream of json data into TypedDict definitions

License

Notifications You must be signed in to change notification settings

rayansostenes/json_to_typed_dict

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON to TypedDict

Converts a stream of json data into TypedDict definitions

Usage

$ cat example.jsonl | ./json2type.py

Running the example above and assuming the following jsonl file:

[{"limit": 0, "price": 0, "value": "", "excess": "No", "coverage": "do", "retention": 0, "bundled_with": "mpl"}]
[{"limit": 0, "price": 0, "value": "", "excess": "Yes", "coverage": "epli", "retention": 0, "bundled_with": "crm"}]
[{"limit": 0, "price": 0, "value": "", "excess": "Yes", "coverage": "fiduciary", "retention": 0, "bundled_with": "epli"}]
[{"limit": 100000, "price": 2000, "value": "", "excess": "No", "coverage": "do", "retention": 2000000, "bundled_with": "Other"}]
[]
[]

The following output will be generated:

import typing as t

class RootDict(t.TypedDict):
    limit: int
    price: int
    value: t.Literal['']
    excess: t.Literal['No', 'Yes']
    coverage: t.Literal['do', 'fiduciary', 'epli']
    retention: int
    bundled_with: t.Literal['Other', 'epli', 'crm', 'mpl']

RootType = list[RootDict]

About

Converts a stream of json data into TypedDict definitions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages