Skip to main content

Converts a JSON Schema to a Plain Old Python Object class

Project description

JSONSchema2PoPo2

Forked from github.com/frx08/jsonschema2popo

A converter to extract 'Plain Old Python Object' classes from JSON Schema files. Similar to the Java project JSONSchema2PoJo. Currently compatible with Python 3.4+ (when using enums, otherwise any version should be fine).

PyPI version Python package

Installation

pip install jsonschema2popo2

Usage

Basic:

jsonschema2popo2 -o /path/to/output_file.py /path/to/json_schema.json

Options:

  • -t, --use-types - Add MyPy typings.
  • -ct, --constructor-type-check - Validate provided types in constructor. Default only type checks when setting property values and not when setting them in the constructor.
  • -s, --use-slots - Add a __slots__ to each generated class to be more memory efficient.
  • --no-generate-from-definitions - Don't generate any classes from the "definitions" section of the schema.
  • --no-generate-from-root-object - Don't generate any classes from the root of the schema.
  • -tp, --translate-properties - Translate property names to be snake_case. With this enabled, inner classes will no longer be prefixed by "_" since their names won't collide with the property name.
  • -l, --language - Language to generate in. Either "js" or "python".

Encode Generated Object to JSON:

import json

g = GeneratedClass()
json.dumps(g.as_dict())

Decode JSON into Generated Object:

import json
g = GeneratedClass.from_dict(json.loads(data))

JSON Schema Format

This library is largely compatible with JSONSchema2PoJo and how that library reads the JSON Schema to generate Java. Specifically, for enumerations, this library supports setting the javaEnumNames array in JSON Schema for an enum to give names to the enum values that will be generated in the Python output.

Project details


Download files

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

Source Distribution

JSONSchema2PoPo2-2.1.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

JSONSchema2PoPo2-2.1.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file JSONSchema2PoPo2-2.1.0.tar.gz.

File metadata

  • Download URL: JSONSchema2PoPo2-2.1.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for JSONSchema2PoPo2-2.1.0.tar.gz
Algorithm Hash digest
SHA256 ca0410ac5a69576b9682ecc8d4ff083d4258b25feb5442ee31b2c984167c7e10
MD5 f703898f4957feb736a2fef1b0f99a3a
BLAKE2b-256 204560d5b22c9b7aa511a144e919aa28f60f92d0de37dc2443915b70b14b3ad0

See more details on using hashes here.

File details

Details for the file JSONSchema2PoPo2-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: JSONSchema2PoPo2-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for JSONSchema2PoPo2-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61bae70a637f9de300e181195454f493e52bc219c09559f82048d7081606fc69
MD5 e605da7ad6ce9e497f505a2ad142faf1
BLAKE2b-256 fa4d8ad228b2df6ce3da016d047ed31352ca60e65ccf0eb9d6341ee68004459e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page