Skip to main content

A simple python module for saving data to JSON files

Project description

JSave

JSave is a simple python module for saving data to JSON files.

PyPI - Version PyPI - Python Version PyPI - License

Table of Contents

Install

To install JSave use pip.

pip3 install jsave

Quick Start

To get started with JSave first import functions from jsave.jsave into your project like this.

from jsave import FUNCTIONS_HERE

To find out what to import, and how to use JSave check out the docs.

Docs

Save

The save function is used to save data - dict to a filepath - str.

from jsave import save

data = {
    "This is some dict in python": "It is very cool"
}

# save data as JSON to file save.json
save(data, "save.json")

Read

The read function is used to read data from a filepath - str.

from jsave import read

print(read("save.json"))
# {"This is some sample data": "Indeed it is"}

If you only want to grab specific keys you can specify them with the keys - [str] parameter.

from jsave import read

print(read("save.json", keys=["Hello"]))
# {"Hello": "World"}

If one of the keys you're searching for dosent exist then you'll get an error like this.

Exception: 'World' could not be loaded, please make sure it is in 'save.json'
(or set parameter 'safe_mode' to False)

If you would like to skip over keys the read function cant find set safe_mode - bool to False.

from jsave import read

print(read("save.json", keys=["Hello", "Guy"], safe_mode=False))
# Cannot find key Guy, but safe_mode is False so it skips over it.
# {"Hello": "World"}

Delete

The read function is used to delete a file provided by filepath - str.

from jsave import delete

delete("save.json")
# file is deleted

Merge

THIS FUNCTION IS CURRENTLY NOT IMPLEMENTED!!!!

The merge function is used to combine multiple files - [str] and save to a output_filepath - str.

from jsave import merge

merge(["save.json", "newsave.json"], "output.json")
# new file named output.json with contents of both save.json and newsave.json.

JSONData

JSONData contains a variety of methods to use on JSON Data, It can be created from a string containing JSON Data, from the read function or from a python dict.

from jsave import JSONData, read

# from string
stringdata = '{"Im some": "Json Data"}'
jdata = JSONData(stringdata)

# from read
jdata = read("save.json")

# from dict
somedata = {
    "Hello": "World"
}

jdata = JSONData(somedata)

prettify

The prettify method returns the JSONData in a pretty format which indent - int size can be specifed.

from jsave import JSONData

# from dict
somedata = {"Hello": "World"}

jdata = JSONData(somedata)

print(jdata.prettify())
#output:
#{
#    "Hello": "World"
#}

print(jdata.prettify(indent=2))
#output:
#{
#  "Hello": "World"
#} 

set_value

The set_value method works in a similar way to setting keys for dicts with some added comfort featues

Set a single value

from jsave import JSONData

# from dict
somedata = {"Hello": "World"}

jdata = JSONData(somedata)

jdata.set_value("Hello", 10)

print(jdata)
# {"Hello": 10}

Set a nested value

from jsave import JSONData

# from dict
somedata = {
    "Hello": {
        "World": 10
    }
}

jdata = JSONData(somedata)

jdata.set_value("Hello/World", 467)

print(jdata)
# {"Hello": {"World": 467}}

Set a value that dosent exist

from jsave import JSONData

# from dict
somedata = {}

jdata = JSONData(somedata)

jdata.set_value("Hello/World", 467)

print(jdata)
# {"Hello": {"World": 467}}

get_value

The get_value method works in a similar way to getting keys from a dict

from jsave import JSONData

# from dict
somedata = {
    "Hello": {
        "World": 10
    }
}

jdata = JSONData(somedata)

print(jdata.get_value("Hello/World"))
# 10

Contributing

All types of contibutions are welcome for the JSave project, whether its updating the documentation, reporting issues, or simply mentioning JSave in your projects.

Remember this before contibuting, you should open an Issue if you don't think you can contribute and open a Pull Request if you have a patch for an issue.

Sections:

Reporting Bugs

Before you submit a bug report make sure you have the following information or are using the following things.

  • Make sure you're on the latest version.
  • Make sure its not just on your end (if you were possibly using a python version we dont support).
  • Check issues to see if it has already been reported.
  • Collect the following info about the bug:
    • Stack Trace.
    • OS, Platform and Version (Windows, Linux, macOS, x86, ARM).
    • Possibly your input and the output.
    • Can you reliably reproduce the issue?

If you have all of that prepared you are more than welcome to open an issue for the community to take a look at.

Enchancements

If you'd like to enchance something please read this checklist:

  • Make sure you're on the latest version.
  • Read the docs and find out if what you want to implement is already a feature.
  • Search to see if the enhancement has already been suggested (No need to open a new issue if its already there!).
  • See if your improvment fits the majority of users, if instead it adds minor functionality consider making a plugin library instead.
  • Describe the enchancement in detail, what does it actually do?

Improve Docs

If you'd like to improve the documentation please go over the following:

  • Read the docs first! If it's already there theres no point adding it.
  • Check issues for ideas, issues are a great place to find documentation to add or edit.
  • Provide examples for the area youre writing for (eg. showing a code example of how to use the save function)

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

jsave-1.2.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

jsave-1.2.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file jsave-1.2.1.tar.gz.

File metadata

  • Download URL: jsave-1.2.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for jsave-1.2.1.tar.gz
Algorithm Hash digest
SHA256 e8b8c0f375ef2ac0ba3cc8e917813f543858c7c83e16c269a56a759abf080066
MD5 762e3ca8f5c43b4d6b2a4c406e0a8b01
BLAKE2b-256 b90fdbca6b278dab9519b6a7c56b30393ad2523bba00a81c7cc4f23e1f21d4e0

See more details on using hashes here.

File details

Details for the file jsave-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: jsave-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for jsave-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 64993e15a9dd4eab11de87339e6652330f488dad6aec8bc4cfe8fc7605c179bc
MD5 8b193030a1a0402596d9e36445d89012
BLAKE2b-256 4a284ab0e8ff434f8835c1673bd7e7f2a706ee7f45e8528eb1fb2ef345752e3a

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