Skip to main content

A simple package providing easy to use JSON utilities

Project description

singlejson

DeepSource GitHub issues PyPI

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

singlejson-0.2.3.tar.gz (15.6 kB view hashes)

Uploaded Source

Built Distribution

singlejson-0.2.3-py3-none-any.whl (16.1 kB view hashes)

Uploaded Python 3

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