Skip to main content

Load and save json files as a global object

Project description

singlejson

GitHub issues PyPI

A very simple set of utilities for working with JSON in Python.

View the documentation here.

Features:

  • Easy loading of JSON files
  • Only one instance for each opened file
  • This library doesn't feature much more, just the basics

Installation:

Install singlejson using pip

pip install singlejson

Usage:

Loading JSON from file:

import singlejson

file = singlejson.load('file.json')  # Load file.json
# Returns a JSONfile object which has the json property
file.json["fun"] = True  # Edit some values in the JSONfile

But if we try to load the same file from the filesystem again, we get the same object:

file2 = singlejson.load('file.json')
print(file2.json["fun"])  # will output True

To save the file back to the disk we call file.save()
Maybe you don't want your program to save file contents only upon successful execution, then you just have to call singlejson.sync() at the end of your program to save all changes to the filesystem.

If the requested file doesn't exist, the file and its parent directories will be created and the "default" values will be written to the file. Should the root "node" of your JSON be a List, you may specify that the default to save is an empty list using singlejson.load(file, default="[]")

Building the documentation locally

The docs are configured to install via an optional dependency group in pyproject.toml (PEP 621). You don’t need a separate requirements.txt.

Quick steps:

# From the project root
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -e .[docs]

# Build HTML docs into docs/_build/html
python -m sphinx -b html docs/source docs/_build/html

Notes:

  • The Sphinx theme is furo. Versions are declared under [project.optional-dependencies].docs in pyproject.toml.
  • For a clean test, use a fresh virtual environment as shown above (preferred over uninstalling global packages).

Contributing:

This is just a fun project of mine mainly to try out python packaging. If you would like to contribute or have a feature-request, please open an issue or pull request.

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

singlejson-0.3.1.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

singlejson-0.3.1-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file singlejson-0.3.1.tar.gz.

File metadata

  • Download URL: singlejson-0.3.1.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for singlejson-0.3.1.tar.gz
Algorithm Hash digest
SHA256 cb88d2d060d59558e63ccc619bfab56132165d1b4db8de338f4f613c7fc3c375
MD5 d732b35785c59a8399a3975fb392c984
BLAKE2b-256 a40d73a9577310f32b4bb4609216f26a71757a6046e2e680a634536442f34f47

See more details on using hashes here.

File details

Details for the file singlejson-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: singlejson-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for singlejson-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f0e8c70ac4da51cacfea2ec56aec3aafbb458f75615b2abc873ac7ab487b53ba
MD5 40f3331eb7acf2b277207214f3d23556
BLAKE2b-256 79bfcd9a557452e87cfa4b72f43d525d6df72a741ea1c797930769eb9f31aa20

See more details on using hashes here.

Supported by

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