No more boilerplate to check and build a Python object from JSON.

Related tags

JSONpythonjsontyping
Overview

JSONloader

This module is for you if you're tired of writing boilerplate that:

  • builds a straightforward Python object from loaded JSON.
  • checks that your input-loaded-JSON has all necessary attributes for your pipeline.
  • checks that your input JSON has the right types.

Example

Main intended usage is through the JSONclass decorator, example below:

>> data['d'] = 1 # Let's fix the missing data >>> example = Example(data) # No more error in loading. >>> >>> >>> # We want to ensure we have *only* annotated parameters >>> data = {'a': 'aa', 'b': 'bb', 'c': 1} >>> @JSONclass(annotations=True, annotations_strict=True) ... class Example: ... a : str ... b : int ... >>> try: ... example = Example(data) ... except KeyError: ... print("error - extra 'c'") ... error - extra 'c' >>> del data['c'] # Let's remove unwanted data >>> example = Example(data) # No more error in loading. >>> >>> # We want to ensure we have only annotated parameters and they >>> # are of annotated type. >>> data = {'a': 'aa', 'b': 'bb'} >>> @JSONclass(annotations=True, annotations_strict=True, annotations_type=True) ... class Example: ... a : str ... b : int ... >>> try: ... example = Example(data) ... except TypeError: ... print("error - b is int") ... error - b is int">
>>> from jsonloader import JSONclass
>>> # By default we don't check for anything, we just build the object
>>> # as we received it.
>>> data = {'a': 'aa', 'b': 'bb', 'c': 1}
>>> @JSONclass
... class Example:
...     pass
...
>>> example = Example(data)
>>> example.a
'aa'
>>> example.b
'bb'
>>>
>>> # We want to ensure we have annotated parameters
>>> data = {'a': 'aa', 'b': 'bb', 'c': 1}
>>> @JSONclass(annotations=True)
... class Example:
...     a : str
...     d : int
...
>>> try:
...     example = Example(data)
... except KeyError:
...     print("error - missing 'd'")
...
error - missing 'd'
>>> data['d'] = 1  # Let's fix the missing data
>>> example = Example(data)  # No more error in loading.
>>>
>>>
>>> # We want to ensure we have *only* annotated parameters
>>> data = {'a': 'aa', 'b': 'bb', 'c': 1}
>>> @JSONclass(annotations=True, annotations_strict=True)
... class Example:
...     a : str
...     b : int
...
>>> try:
...     example = Example(data)
... except KeyError:
...     print("error - extra 'c'")
...
error - extra 'c'
>>> del data['c']  # Let's remove unwanted data
>>> example = Example(data)  # No more error in loading.
>>>
>>> # We want to ensure we have only annotated parameters and they
>>> # are of annotated type.
>>> data = {'a': 'aa', 'b': 'bb'}
>>> @JSONclass(annotations=True, annotations_strict=True, annotations_type=True)
... class Example:
...     a : str
...     b : int
...
>>> try:
...     example = Example(data)
... except TypeError:
...     print("error - b is int")
...
error - b is int

Install

User installation

python3 -m virtualenv venv
. venv/bin/activate
pip3 install jsonloader

Developer installation

Github repository currently points to latest development version. Please jump to latest released version tag if you intend to work on PyPI version. For example git checkout tags/0.4.2.

python3 -m virtualenv venv
. venv/bin/activate
pip3 install -e '.[dev]'

Run Tests

# From this repository top directory
nose2 -t . --with-doctest

Tests coverage

For example, leverage coverage module: nose2 -t . -C --coverage-report html

Marshall python objects to and from JSON

Pymarshaler - Marshal and Unmarshal Python Objects Disclaimer This tool is in no way production ready About Pymarshaler allows you to marshal and unma

Hernan Romer 9 Dec 20, 2022
Atom, RSS and JSON feed parser for Python 3

Atoma Atom, RSS and JSON feed parser for Python 3. Quickstart Install Atoma with pip: pip install atoma

Nicolas Le Manchet 95 Nov 28, 2022
Random JSON Key:Pair Json Generator

Random JSON Key:Value Pair Generator This simple script take an engish dictionary of words and and makes random key value pairs. The dictionary has ap

Chris Edwards 1 Oct 14, 2021
Define your JSON schema as Python dataclasses

Define your JSON schema as Python dataclasses

62 Sep 20, 2022
Python script to extract news from RSS feeds and save it as json.

Python script to extract news from RSS feeds and save it as json.

Alex Trbznk 14 Dec 22, 2022
No more boilerplate to check and build a Python object from JSON.

JSONloader This module is for you if you're tired of writing boilerplate that: builds a straightforward Python object from loaded JSON. checks that yo

3 Feb 05, 2022
Simple Python Library to convert JSON to XML

json2xml Simple Python Library to convert JSON to XML

Vinit Kumar 79 Nov 11, 2022
cysimdjson - Very fast Python JSON parsing library

Fast JSON parsing library for Python, 7-12 times faster than standard Python JSON parser.

TeskaLabs 235 Dec 29, 2022
Json GUI for No Man's Sky save file

NMS-Save-Parser Json GUI for No Man's Sky save file GUI python NMS_SAVE_PARSER.py [optional|save.hg] converter only python convert.py usage: conver

2 Oct 19, 2022
Small python wrapper around the valico rust library to provide fast JSON schema validation.

Small python wrapper around the valico rust library to provide fast JSON schema validation.

Simon J Knibbs 5 Jul 12, 2019
Convert Wii UI formats to JSON5 and vice versa

Convert Wii UI formats to JSON5 and vice versa

Pablo Stebler 11 Aug 28, 2022
JSON Schema validation library

jsonschema A JSON Schema validator implementation. It compiles schema into a validation tree to have validation as fast as possible. Supported drafts:

Dmitry Dygalo 309 Jan 01, 2023
Wikidot-forum-dump - Simple Python script that dumps a Wikidot wiki forum into JSON structures.

wikidot-forum-dump Script is partially based on 2stacks by bluesoul: https://github.com/scuttle/2stacks To dump a Wiki's forum, edit config.py and put

ZZYZX 1 Jun 29, 2022
A JSON API for returning Godspeak sentences. Based on the works of Terry A Davis (Rest in Peace, King)

GodspeakAPI A simple API for generating random words ("godspeaks"), inspired by the works of Terrence Andrew Davis (Rest In Peace, King). Installation

Eccentrici 3 Jan 24, 2022
MOSP is a platform for creating, editing and sharing validated JSON objects of any type.

MONARC Objects Sharing Platform Presentation MOSP is a platform for creating, editing and sharing validated JSON objects of any type. You can use any

CASES Luxembourg 72 Dec 14, 2022
Roamtologseq - A script loads a json export of a Roam graph and cleans it up for import into Logseq

Roam to Logseq The script loads a json export of a Roam graph and cleans it up f

Sebastian Pech 4 Mar 07, 2022
With the help of json txt you can use your txt file as a json file in a very simple way

json txt With the help of json txt you can use your txt file as a json file in a very simple way Dependencies re filemod pip install filemod Installat

Kshitij 1 Dec 14, 2022
A query expression for extracting data from JSON.

JSONPATH A selector expression for extracting data from JSON. Quickstarts Installation Install the stable version from PYPI. pip install jsonpath-extr

林玮 (Jade Lin) 33 Oct 22, 2022
JSON for Modern C++ Release Scripts

JSON for Modern C++ Release Scripts Preparations Install required tools: make install_requirements. Add required keys to config.json (apparently not c

Niels Lohmann 4 Sep 19, 2022
Low code JSON to extract data in one line

JSON Inline Low code JSON to extract data in one line ENG RU Installation pip install json-inline Usage Rules Modificator Description ?key:value Searc

Aleksandr Sokolov 12 Mar 09, 2022