Skip to main content

PyPI Build Status Coverage Report

jsonstore

This module provides a class that maps keys and values from a JSON file onto its attributes.

The goal was to provide a convenient way of loading and saving configuration in a familiar human readable format. This is a bit more flexible than the configparser module which is included with Python.

This works is tested and working on Python 2.7 and Python 3.6+. It will not work on 2.6 or lower. The tests are also executed on PyPy.

Examples

Basics

# by default JsonStore commits on every change unless in a transaction
store = JsonStore('config.json')
store.a_string = "something"
store.a_list = [1, 2, 3]
store.a_dictionary = {
  'dict-list': [{}],
  'ln(2)': 0.69314718056,
  'for-you': u"💐",
}

# you can use […] to set/get/delete string keys
store['some_key'] = "a value"
# the key is split on '.'s and works on dictionaries
del store['a_dictionary.dict-list']
store['a_dictionary.new_value'] = "old value"
#  you can also use the syntactic sugar for tuple keys (explicit lists work too)
assert store['a_dictionary', 'new_value'] == "old value"
# you can traverse lists too
assert store['a_list', -1] == 3
# you can use slices in lists
assert len(store['a_list', 1:]) == 2
del store['a_list', :2]
assert store.a_list == [3]

# deep copies are made when assigning values
my_list = ['fun']
store.a_list = my_list
assert store.a_list is not my_list
assert 'a_list' in store

# deep copies are also returned to avoid unsanitary changes being made
store.a_dictionary['new_value'] = "new value"  # won't update the store!
assert store.a_dictionary['new_value'] == "old value"
assert store.a_dictionary is not store.a_dictionary

# Appending to, extending a list
>>> store.list = [1, 2, 3]

# Because of the fact that .append won't modify the list in the actual file,
# but only a copy...
>>> store.list.append(4)
>>> store.list
[1, 2, 3]

# ... we need to rather use the += operator to append to a list.
>>> store.list += [4]
>>> store.list
[1, 2, 3, 4]

# Similarly, we can extend the list
>>> store.list += [5, 6]
>>> store.list
[1, 2, 3, 4, 5, 6]

Transactions

JsonStore objects can be used as context managers to provide transactions which are rolled back in the event of an exception. The transaction model is primitive; you can only nest transactions.

While a store is put into a transaction, it will not save changes to file until all of the transactions have been closed.

from jsonstore import JsonStore

# even with auto_commit=True, the file won't be saved until the last contexts has been closed
with JsonStore('config.json', indent=None, auto_commit=False) as store:
  self.value = 1

# the context manager will roll back changes made if an exception is raised
store = JsonStore('config.json', indent=None)
try:
  with store:
    store.value = "new"
    raise Exception
except Exception:
  pass
# here we see the value that was saved previously
assert store.value == 1

Metadata

Release files for python-jsonstore 1.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-jsonstore 1.3.3
File Size Uploaded
python_jsonstore-1.3.3.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-jsonstore 1.3.3
File Interpreter ABI Platform
python_jsonstore-1.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.3 kB

Release files / python_jsonstore-1.3.3.tar.gz

Download URL python_jsonstore-1.3.3.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
39cb537ce63af179e425b662d62dfdf93d2dac9de7e0e4d4332926533f0b4d3f
BLAKE2b-256 checksum
How to use checksums
5f34fe92cbfc6a151c4cda14647aa772ed1486c39ffe3248201870fbd31dd1e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2025.

Transparency log

Release files / python_jsonstore-1.3.3-py3-none-any.whl

Download URL python_jsonstore-1.3.3-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03b70d5416166d287d0e5fd8f404925ed956d66af85fd5e38687e8f2c6d912ec
BLAKE2b-256 checksum
How to use checksums
2421989283518e0e685da09fa60fd023369cb8ac9c10a2964ad0218599e9ff0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.3.3 This release

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page