Skip to main content

A Python package for making your life of working with json's, easier

Project description

JSONMaster

JSONMaster is a Python package designed to provide a collection of utilities for working with JSON data. Whatever you are doing with jsons, JSONMaster,aims to simplify your workflow and enhance your productivity.

Features

  • Easy Parsing: Effortlessly parse JSON strings into Python objects.
  • Transformation: Transform JSON structures with intuitive functions to namespaces or dataclasses.
  • File I/O: Simplify reading from and writing to JSON files.

Installation

You can install BetterJSON via pip:

pip install jsonmaster

Usage

Reading a json file

Read a json from a file path

from jsonmaster import open_json, JsonFile

# easy option
with open_json("jsonfile.json") as jf:
    print(jf.dict())

# configurable option
with JsonFile(file_path="jsonfile.json", sort_keys=True, immediate_flush=True, prettify=True) as jf:
    print(jf.dict())

Using regular json package

All regular json package capabilities are imported inside jsonmaster

import jsonmaster

data: str = '{"name": "Alice", "age": 30}'

d: dict = jsonmaster.loads(data)

print(jsonmaster.dumps(d))

# ...

Accessing json as a namespace

Use your jsons as an actual python class

from jsonmaster import open_json, JsonNamespace

# jsonfile.json contains {"key": "value"}
with open_json("jsonfile.json") as jf:
    namespace: JsonNamespace = jf.namespace()
    
    # access the key 
    print(namespace.key)
    
    # set will not affect the original file

File I/O

Read and write JSON files easily:

from jsonmaster import open_json

# jsonfile.json contains {"key": "value"}
with open_json("jsonfile.json") as jf:
    # Adding a new key to the json file
    jf["new_key"] = "new_value"
    
    # Accessing an existing key in the json file
    print(jf["old_key"])
    print(jf["new_key"])

Dataclasses

Load your json file into your pydantic BaseModel easily

from jsonmaster import open_json
from pydantic import BaseModel


class MyModel(BaseModel):
    my_model_str_key: str
    my_model_int_key: int


with open_json('jsonfile.json') as jf:
    m: MyModel = jf.dataclass(MyModel)
    print(m.my_model_str_key)

Contributing

We welcome contributions! Please read our Contributing Guidelines for details on how to get started.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Author

Created by Ethan Lerner.

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

jsonmaster-1.0.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

jsonmaster-1.0.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file jsonmaster-1.0.1.tar.gz.

File metadata

  • Download URL: jsonmaster-1.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.13

File hashes

Hashes for jsonmaster-1.0.1.tar.gz
Algorithm Hash digest
SHA256 315ffad0adcaebbc7074ea2a6bb86378f8ec607a51028cf03bd36544171bbbd6
MD5 cca2e24f7b23e0ee5d4eef698cd4453c
BLAKE2b-256 620247bb9f238a7934570fe58fff4e905d2c6735620dc4a5027311df8bb4726d

See more details on using hashes here.

File details

Details for the file jsonmaster-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: jsonmaster-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.13

File hashes

Hashes for jsonmaster-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5820d8fcefa63a8eebd3723fb9384c1e11a11f9336bf814da2fbb2fd4cd23050
MD5 73b71f597f5959558504e44a3fb78713
BLAKE2b-256 9e11a5f493574febf4ffe6086db80956dd6e6ed71aeb433137a4be028619d958

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