Skip to main content

JSON decoding for Python with type hinting (PEP 484)

Project description


License Pypi CI

JSON decoding for Python with type hinting (PEP 484).

Requirements and Restrictions

  • Python >= 3.6
  • Mypy <= 0.770
  • Use non-generic or parameterized class to decode JSON.
  • Use type hints without forward references.


  • Support decoding types as below:
    • primitive types like str, int, float, bool and None.
    • Union and Optional.
    • homogeneous and heterogeneous Tuple and List.
    • variable-length Tuple.
    • non-generic and parameterized dataclasses.
  • Support API like json.load and json.loads.


from typing import Optional

import typedjson
from dataclasses import dataclass

class NameJson:
    first: str
    last: Optional[str]

class CatJson:
    id: str
    age: int
    name: Optional[NameJson]

json = {
    'id': 'test-cat',
    'age': 13,
    'name': {
        'first': 'Jiji',

print(typedjson.decode(CatJson, json))  # Output: CatJson(id='test-cat', age=13, name=NameJson(first='Jiji', last=None))

print(typedjson.decode(CatJson, {}))  # Output: DecodingError(TypeMismatch(('id',)))

Please refer to test codes for more detail.


Please read


  • Prohibit decoding Set and Dict explicitly.
  • Provide the API document.
  • Explain why typedjson uses undocumented APIs.
  • Explain what typedjson resolves.
  • Improve API to dump like json.dump and json.dumps.
    • Provide mypy plugin to check whether the class is encodable as JSON or not with @typedjson.encodable decorator.
  • Improve the peformance of typedjson.decode.
  • Support type hints with forward reference.
  • Support TypedDict.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for typedjson, version 0.10.4
Filename, size File type Python version Upload date Hashes
Filename, size typedjson-0.10.4-py3-none-any.whl (6.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size typedjson-0.10.4.tar.gz (5.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page