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

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 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
A Cobalt Strike Scanner that retrieves detected Team Server beacons into a JSON object

melting-cobalt 👀 A tool to hunt/mine for Cobalt Strike beacons and "reduce" their beacon configuration for later indexing. Hunts can either be expans

Splunk GitHub 150 Nov 23, 2022
Simple, minimal conversion of Bus Open Data Service SIRI-VM data to JSON

Simple, minimal conversion of Bus Open Data Service SIRI-VM data to JSON

Andy Middleton 0 Jan 22, 2022
json|dict to python object

Pyonize convert json|dict to python object Setup pip install pyonize Examples from pyonize import pyonize

bilal alpaslan 45 Nov 25, 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
A fast streaming JSON parser for Python that generates SAX-like events using yajl

json-streamer jsonstreamer provides a SAX-like push parser via the JSONStreamer class and a 'object' parser via the ObjectStreamer class which emits t

Kashif Razzaqui 196 Dec 15, 2022
Console to handle object storage using JSON serialization and deserealization.

Console to handle object storage using JSON serialization and deserealization. This is a team project to develop a Python3 console that emulates the AirBnb object management.

Ronald Alexander 3 Dec 03, 2022
Ibmi-json-beautify - Beautify json string with python

Ibmi-json-beautify - Beautify json string with python

Jefferson Vaughn 3 Feb 02, 2022
Make JSON serialization easier

Make JSON serialization easier

4 Jun 30, 2022
JSON Interoperability Vulnerability Labs

JSON Interoperability Vulnerability Labs Description These are the companion labs to my research article "An Exploration of JSON Interoperability Vuln

Bishop Fox 168 Dec 25, 2022
Convert your subscriptions csv file into a valid json for Newpipe!

Newpipe-CSV-Fixer Convert your Google subscriptions CSV file into a valid JSON for Newpipe! Thanks to nikcorg for sharing how to convert the CSV into

Juanjo 44 Dec 29, 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
Convert Wii UI formats to JSON5 and vice versa

Convert Wii UI formats to JSON5 and vice versa

Pablo Stebler 11 Aug 28, 2022
Fileson - JSON File database tools

Fileson is a set of Python scripts to create JSON file databases

Joonas Pihlajamaa 2 Feb 02, 2022
JsonParser - Parsing the Json file by provide the node name

Json Parser This project is based on Parsing the json and dumping it to CSV via

Ananta R. Pant 3 Aug 08, 2022
simdjson : Parsing gigabytes of JSON per second

JSON is everywhere on the Internet. Servers spend a *lot* of time parsing it. We need a fresh approach. The simdjson library uses commonly available SIMD instructions and microparallel algorithms to

16.3k Dec 29, 2022
A Python tool that parses JSON documents using JsonPath

A Python tool that parses JSON documents using JsonPath

8 Dec 18, 2022
Editor for json/standard python data

Editor for json/standard python data

1 Dec 07, 2021
import json files directly in your python scripts

Install Install from git repository pip install git+https://github.com/zaghaghi/direct-json-import.git Use With the following json in a file named inf

Hamed Zaghaghi 51 Dec 01, 2021