Skip to main content

An implementation of JSON data generator from JSON Schema for Python

Project description

IN SHORT

jsonfromschema is used to generate JSON data (file .json) from JSON Schema (.json, see https://json-schema.org) Project is written in Python for Python purposes, but it is also stand-alone tool.

SPDX-License-Identifier: 0BSD

Project name: jsonfromschema License: 0BSD / Free Public License 1.0.0 More information about license: https://opensource.org/licenses/0BSD

NON-INSTALL

git clone git@github.com:NIC-MichalLabedzki/jsonfromschema.git

You can run it from sources without any dependancies* (python and some modules delivered with it)

python ./jsonfromschema

See:

python ./jsonfromschema --help

See CLI section for more details.

INSTALLATION

pip install jsonfromschema

or

pip install -e git@github.com:NIC-MichalLabedzki/jsonfromschema.git

or

pip install -e https://github.com/NIC-MichalLabedzki/jsonfromschema.git

or

git clone git@github.com:NIC-MichalLabedzki/jsonfromschema.git
cd jsonfromschema
python setup.py # or pip install -e .

INTERFACE

There are two kind of interfaces: CLI and Python module.

CLI

CLI is Command Line Interface. So you have tool called: jsonfromschema

$ jsonfromschema --help
usage: jsonfromschema [-h] [-v] [-w [VALIDATE]] [--no-default] [--no-examples] [--maximum]
         [--subschema SUBSCHEMA] [--from-python-package FROM_PYTHON_PACKAGE]
         schema output

Generate JSON data file (*.json) from JSON Schema

positional arguments:
schema                path to JSON Schema file or python packages resource
                        [--from-python-package]
output                path to JSON data output file

optional arguments:
-h, --help            show this help message and exit
-v, --verbose         verbose mode
-w [VALIDATE], --validate [VALIDATE]
                        use jsonschema to validate output and check if schema
                        is valid [3,4,6,7 (default)]
--no-default          do not use 'default' fields in jsonschema
--no-examples         do not use 'default' fields in jsonschema
--maximum             generate as complex json as possible (by
                        implementation); for example ignore "required" and
                        favor "object" over less complicated fields
--subschema SUBSCHEMA
                        extract subschema only by this json fragment pointer
--from-python-package FROM_PYTHON_PACKAGE
                        'schema' is path to python package resource, this
                        option needs package name as argument

Some examples:

$ jsonfromschema input_schema.json output_json_data.json

Verbose:

$ jsonfromschema input_schema.json output_json_data.json -v

Validate output: It use “jsonschema” module (pip install jsonschema) to validate output json to be valid with given schema.

$ jsonfromschema input_schema.json output_json_data.json -w

Generate subschema: Use JSON pointer (schema side) to generate only part of schema:

$ jsonfromschema tests/test_schema_main.json.json output.json -w --subschema=/properties/string_default
$ cat output.json
"foo"

Use JSON Schema resources from some python packages:

$ jsonfromschema ../tests/test_schema_main.json output.json -vw --subschema=/properties/string_default --from-python-package jsonfromschema
$ cat output.json
"foo"

Python Module

API is not stable right now.

import jsonfromschema.lib
generate_dict_from_text(root_name, schema_text, optional_args=None)
generate_dict_from_file(schema_file, optional_args=None)
generate_dict_from_package(package, path, optional_args=None)
optional_args:

Default values are:

{
'verbose': False,
'no-default': False,
'no-examples': False,
'maximum': False,
'pkg_resource_root': None,
'subschema': None,
}
Where:

pkg_resource_root is package name, for example “jsonschema”

Changelog

v0.1.4:
  1. try use –maximum value for more json types

  2. remove anoying python version from cli output

TODO

  1. JsonSchema Draft-7 support (in progress)

  2. Check Draft-4 support

  3. Section about Contributions

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

jsonfromschema-0.1.4.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

jsonfromschema-0.1.4-py2.py3-none-any.whl (10.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file jsonfromschema-0.1.4.tar.gz.

File metadata

  • Download URL: jsonfromschema-0.1.4.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.5

File hashes

Hashes for jsonfromschema-0.1.4.tar.gz
Algorithm Hash digest
SHA256 88fda249008c161821a59e3a9908215281f3a63c39fec0ed5e9bcc3dd80308bc
MD5 5deb60758c099df1fafc7e9464d31ad5
BLAKE2b-256 4f3c0c7e0d8bc922e24dad1bce8d9ac51704b270828753843f106b603abb487c

See more details on using hashes here.

File details

Details for the file jsonfromschema-0.1.4-py2.py3-none-any.whl.

File metadata

  • Download URL: jsonfromschema-0.1.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.5

File hashes

Hashes for jsonfromschema-0.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cb5cec7eba45120e7c783244ab59152529d316818c0b4b73cd18ed488f24b1b5
MD5 81d47282ca6d45c9eaff4adcbd7a51df
BLAKE2b-256 fa073dd8398814f56add6797b960dc571e759ebf0600ac89223737cb85747245

See more details on using hashes here.

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