A simple package providing easy to use JSON utilities
Project description
singlejson
A very simple set of utilities for working with JSON in Python.
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="[]")
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
Built Distribution
File details
Details for the file singlejson-0.2.3.tar.gz
.
File metadata
- Download URL: singlejson-0.2.3.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06a5c326bbe6a1bd629dcd9eb8be32362a65465d66f2253d5bb2514993bd94a1 |
|
MD5 | dbd8c4841c5ebb16092b5d466296966c |
|
BLAKE2b-256 | 8bec4d4c0c13ca249ec8c2095bb1d9e94cf9b8ef08318051dc8aeba79dd8b518 |
File details
Details for the file singlejson-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: singlejson-0.2.3-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2480b6ea946c3f8bb267a8794b2e7d2515a0037db0b3ce8bbea94af5d142a7c4 |
|
MD5 | e05b0dbfe434e16e39c18dd39b6355bf |
|
BLAKE2b-256 | 1356e17dcd9ac670c7cd6398b0ec61fc2b11ae58790e4c99eac55da953b54663 |