Skip to main content

Load and save json files as a global object

Project description

singlejson

GitHub issues PyPI

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

View the documentation here.

Features:

  • Easy loading of JSON files
  • One instance for each opened file
  • Multiple ways of handling default values

Installation:

Install singlejson using pip

pip install singlejson

Usage:

Loading JSON from a 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

When we load the same file from the filesystem again, we get the same object:

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

To save the file back to the disk we call file.save()

If the requested file doesn't exist, the file and its parent directories will be created and default_data will be written.

import singlejson
file = singlejson.load('new_file.json', default_data={"fun": False})
print(file.json)  # > {"fun": False}

Or initialize the file with a default file path:

import singlejson
file = singlejson.load('auth.json', default_path='defaults/auth.json')

This way you can commit default files to your repository. If the file doesn't exist or is corrupt, the default file will be copied to the requested location.

For more detailed information, visit the documentation

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.4.2.tar.gz (86.9 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.4.2-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: singlejson-0.4.2.tar.gz
  • Upload date:
  • Size: 86.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for singlejson-0.4.2.tar.gz
Algorithm Hash digest
SHA256 9029acf85ddb377fd32bfc43d1bbf367d8b3083cf1a4653427113e722493dbca
MD5 9816ebb6a9427b407ae5d291f4029f1e
BLAKE2b-256 a9bfa3b3a32e0c9d237fd107c0ec65213e3e7ef79e80fa49957c0382143a88f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for singlejson-0.4.2.tar.gz:

Publisher: publish.yml on IgnyteX-Labs/singlejson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: singlejson-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for singlejson-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 06d89d82130b5712c9293b6a76124d9289965c3d27b17444dd902227bae749d5
MD5 28bfc4ff48a3f7db2246b5c43ef90687
BLAKE2b-256 bbbf49e28fc6c50b86eae6cf805ffb3a0ee4d4ce2daf2c630017c40771e723e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for singlejson-0.4.2-py3-none-any.whl:

Publisher: publish.yml on IgnyteX-Labs/singlejson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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