Skip to main content

No project description provided

Project description

A simple package that convert dictionary or a list into json-schema using the OpenAPI standards.

Installation

to-json-schema can be installed via pip:

$ pip install to-json-schema

Quickstart

You can now convert your python dict into json-schema:

from to_json_schema.to_json_schema import SchemaBuilder

 data = {
     "country": "Pakistan",
     "city": "Karachi",
     "population": 16051521,
     "is_capital": False,
     "key_qualities": ["food", "multi-cultural"],
 }

 schema_builder = SchemaBuilder()
 json_schema = schema_builder.to_json_schema(data)

 >>> {'type': 'object', 'properties': {'country': {'type': 'string'}, 'city': {'type': 'string'}, 'population': {'type': 'integer'}, 'is_capital': {'type': 'boolean'}, 'key_qualities': {'type': 'array', 'items': {'type': 'string'}}}}

You can also convert list of dict, string, integer into-json schema

from to_json_schema.to_json_schema import SchemaBuilder

data = [{"foo": 12, "bar": 14}, {"moo": 52, "car": 641}, {"doo": 6, "tar": 84}]

schema_builder = SchemaBuilder()
json_schema = schema_builder.to_json_schema(data)

>>> {'type': 'array', 'items': {'type': 'object', 'properties': {'foo': {'type': 'integer'}, 'bar': {'type': 'integer'}, 'moo': {'type': 'integer'}, 'car': {'type': 'integer'}, 'doo': {'type': 'integer'}, 'tar': {'type': 'integer'}}}}

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

to_json_schema-1.0.1.tar.gz (14.0 kB view hashes)

Uploaded Source

Built Distribution

to_json_schema-1.0.1-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

Supported by

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