Name | jsave JSON |
Version |
1.4.2
JSON |
| download |
home_page | None |
Summary | A simple python module for saving data to JSON files |
upload_time | 2024-10-26 15:44:35 |
maintainer | None |
docs_url | None |
author | Ethan Illingsworth |
requires_python | <4.0,>=3.9 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# JSave
JSave is a simple python module for operating on JSON files.
![PyPI - Version](https://img.shields.io/pypi/v/jsave)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/jsave)
![PyPI - License](https://img.shields.io/pypi/l/jsave)
## Table of Contents
* [Install](#install)
* [Quick Start](#quick-start)
* [Docs](#docs)
* [Contributing](#contributing)
## Install
To install JSave use `pip`.
```
pip3 install jsave
```
## Quick Start
To get started with JSave first import functions from `jsave` into your project like this.
```py
from jsave import FUNCTIONS_HERE
```
To find out what to import, and how to use JSave check out the [docs](#docs).
## Docs
### JFile/JSONFile
The JFile class is what it sounds like, providing all the neccessary methods to manipulate the specified filepath.
Args:
`filepath (string)`
#### Save
Saves a python dict to filepath as JSON data
Args:
`data (dict)`
`indent (int) = 4`
Returns:
`JData that was written to file`
```py
from jsave import JFile
data = {
"This is some dict in python": "It is very cool"
}
file = JFile("save.json")
# save data as JSON to file save.json
file.save(data, 4)
```
#### Read
Reads a JSON file.
Args:
`keys (StringList) = []`
`safe_mode (bool) = True`
Returns:
`JSONData from file`
```py
from jsave import JFile
file = JFile("save.json")
print(file.read())
# {"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.
```py
from jsave import JFile
file = JFile("save.json")
print(file.read(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`.
```py
from jsave import JFile
file = JFile("save.json")
print(file.read(keys=["Hello", "Guy"], safe_mode=False))
# Cannot find key Guy, but safe_mode is False so it skips over it.
# {"Hello": "World"}
```
#### Delete
Delete a file at the specified filepath.
```py
from jsave import JFile
file = JFile("save.json")
file.delete()
# file is deleted
```
### Update
Update value at key for specified filepath.
Args:
`key (str)`
`value (object)`
```py
from jsave import JFile
file = JFile("save.json")
file.update("Hello/World", 10)
print(file.read())
# {"will not overwrite": true, "Hello":{"World": 10}}
```
### JData
JData contains a variety of methods to use on JSON Data
Args:
data (str || dict)
```py
from jsave import JData, JFile
# from string
stringdata = '{"Im some": "Json Data"}'
jdata = JData(stringdata)
# from read
file = JFile("save.json")
jdata = file.read()
# from dict
somedata = {
"Hello": "World"
}
jdata = JData(somedata)
```
#### prettify
Returns JData with formating
Args:
indent (int) = 4
Returns:
JData as str with formmating
```py
from jsave import JData
# from dict
somedata = {"Hello": "World"}
jdata = JData(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
Args:
key (str)
value (object)
Set a single value
```py
from jsave import JData
# from dict
somedata = {"Hello": "World"}
jdata = JData(somedata)
jdata.set_value("Hello", 10)
print(jdata)
# {"Hello": 10}
```
Set a nested value
```py
from jsave import JData
# from dict
somedata = {
"Hello": {
"World": 10
}
}
jdata = JData(somedata)
jdata.set_value("Hello/World", 467)
print(jdata)
# {"Hello": {"World": 467}}
```
Set a value that dosent exist
```py
from jsave import JData
# from dict
somedata = {}
jdata = JData(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
Args:
key (str)
Returns:
Value at key
```py
from jsave import JData
# from dict
somedata = {
"Hello": {
"World": 10
}
}
jdata = JData(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](#reporting-bugs)
* [Enchancements](#enchancements)
* [Improve Docs](#improve-docs)
### 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](#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](#docs) please go over the following:
* Read the [docs](#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)
Raw data
{
"_id": null,
"home_page": null,
"name": "jsave",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Ethan Illingsworth",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/5a/c0/54145cd33d17b992f3e91f8bb5818ee15ef3648135e069b28177ae1409f9/jsave-1.4.2.tar.gz",
"platform": null,
"description": "# JSave\nJSave is a simple python module for operating on JSON files.\n\n![PyPI - Version](https://img.shields.io/pypi/v/jsave)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/jsave)\n![PyPI - License](https://img.shields.io/pypi/l/jsave)\n\n## Table of Contents\n* [Install](#install)\n* [Quick Start](#quick-start)\n* [Docs](#docs)\n* [Contributing](#contributing)\n\n## Install\nTo install JSave use `pip`.\n```\npip3 install jsave\n```\n\n## Quick Start\nTo get started with JSave first import functions from `jsave` into your project like this.\n```py\nfrom jsave import FUNCTIONS_HERE\n```\n\nTo find out what to import, and how to use JSave check out the [docs](#docs).\n\n\n## Docs\n\n### JFile/JSONFile\nThe JFile class is what it sounds like, providing all the neccessary methods to manipulate the specified filepath.\n\nArgs:\n\n`filepath (string)`\n\n\n#### Save\nSaves a python dict to filepath as JSON data\n\nArgs:\n\n`data (dict)`\n\n`indent (int) = 4`\n\nReturns:\n\n`JData that was written to file`\n\n```py\nfrom jsave import JFile\n\ndata = {\n \"This is some dict in python\": \"It is very cool\"\n}\n\nfile = JFile(\"save.json\")\n\n# save data as JSON to file save.json\nfile.save(data, 4)\n```\n\n\n#### Read\nReads a JSON file.\n\nArgs:\n\n`keys (StringList) = []`\n\n`safe_mode (bool) = True`\n\nReturns:\n\n`JSONData from file`\n\n```py\nfrom jsave import JFile\n\nfile = JFile(\"save.json\")\n\nprint(file.read())\n# {\"This is some sample data\": \"Indeed it is\"}\n```\n\nIf you only want to grab specific keys you can specify them with the `keys - [str]` parameter.\n\n```py\nfrom jsave import JFile\n\nfile = JFile(\"save.json\")\n\nprint(file.read(keys=[\"Hello\"]))\n# {\"Hello\": \"World\"}\n```\n\nIf one of the keys you're searching for dosent exist then you'll get an error like this.\n```\nException: 'World' could not be loaded, please make sure it is in 'save.json'\n(or set parameter 'safe_mode' to False)\n```\n\nIf you would like to skip over keys the read function cant find, set `safe_mode - bool` to `False`.\n\n```py\nfrom jsave import JFile\n\nfile = JFile(\"save.json\")\n\nprint(file.read(keys=[\"Hello\", \"Guy\"], safe_mode=False))\n# Cannot find key Guy, but safe_mode is False so it skips over it.\n# {\"Hello\": \"World\"}\n```\n\n#### Delete\nDelete a file at the specified filepath.\n\n```py\nfrom jsave import JFile\n\nfile = JFile(\"save.json\")\n\nfile.delete()\n# file is deleted\n```\n\n### Update\n\nUpdate value at key for specified filepath.\n\nArgs:\n\n`key (str)`\n\n`value (object)`\n\n```py\nfrom jsave import JFile\n\nfile = JFile(\"save.json\")\n\nfile.update(\"Hello/World\", 10)\n\nprint(file.read())\n# {\"will not overwrite\": true, \"Hello\":{\"World\": 10}}\n\n```\n\n### JData\nJData contains a variety of methods to use on JSON Data\n\nArgs:\n data (str || dict)\n\n```py\nfrom jsave import JData, JFile\n\n# from string\nstringdata = '{\"Im some\": \"Json Data\"}'\njdata = JData(stringdata)\n\n# from read\nfile = JFile(\"save.json\")\njdata = file.read()\n\n# from dict\nsomedata = {\n \"Hello\": \"World\"\n}\n\njdata = JData(somedata)\n```\n\n#### prettify\nReturns JData with formating\n\nArgs:\n indent (int) = 4\n\nReturns:\n JData as str with formmating\n\n```py\nfrom jsave import JData\n\n# from dict\nsomedata = {\"Hello\": \"World\"}\n\njdata = JData(somedata)\n\nprint(jdata.prettify())\n#output:\n#{\n# \"Hello\": \"World\"\n#}\n\nprint(jdata.prettify(indent=2))\n#output:\n#{\n# \"Hello\": \"World\"\n#} \n```\n\n#### set_value\nThe set_value method works in a similar way to setting keys for dicts with some added comfort featues\n\nArgs:\n key (str)\n value (object)\n\nSet a single value\n```py\nfrom jsave import JData\n\n# from dict\nsomedata = {\"Hello\": \"World\"}\n\njdata = JData(somedata)\n\njdata.set_value(\"Hello\", 10)\n\nprint(jdata)\n# {\"Hello\": 10}\n```\n\n\nSet a nested value\n```py\nfrom jsave import JData\n\n# from dict\nsomedata = {\n \"Hello\": {\n \"World\": 10\n }\n}\n\njdata = JData(somedata)\n\njdata.set_value(\"Hello/World\", 467)\n\nprint(jdata)\n# {\"Hello\": {\"World\": 467}}\n```\n\nSet a value that dosent exist\n```py\nfrom jsave import JData\n\n# from dict\nsomedata = {}\n\njdata = JData(somedata)\n\njdata.set_value(\"Hello/World\", 467)\n\nprint(jdata)\n# {\"Hello\": {\"World\": 467}}\n```\n\n#### get_value\nThe get_value method works in a similar way to getting keys from a dict\n\nArgs:\n key (str)\n\nReturns:\n Value at key\n\n```py\nfrom jsave import JData\n\n# from dict\nsomedata = {\n \"Hello\": {\n \"World\": 10\n }\n}\n\njdata = JData(somedata)\n\nprint(jdata.get_value(\"Hello/World\"))\n# 10\n```\n\n## Contributing\nAll types of contibutions are welcome for the JSave project, whether its updating the documentation, reporting issues, or simply mentioning JSave in your projects.\n\nRemember 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.\n\nSections:\n* [Reporting Bugs](#reporting-bugs)\n* [Enchancements](#enchancements)\n* [Improve Docs](#improve-docs)\n\n\n### Reporting Bugs\nBefore you submit a bug report make sure you have the following information or are using the following things.\n\n* Make sure you're on the latest version.\n* Make sure its not just on your end (if you were possibly using a python version we dont support).\n* Check issues to see if it has already been reported.\n* Collect the following info about the bug:\n * Stack Trace.\n * OS, Platform and Version (Windows, Linux, macOS, x86, ARM).\n * Possibly your input and the output.\n * Can you reliably reproduce the issue?\n\nIf you have all of that prepared you are more than welcome to open an issue for the community to take a look at.\n\n### Enchancements\nIf you'd like to enchance something please read this checklist:\n\n* Make sure you're on the latest version.\n* Read the [docs](#docs) and find out if what you want to implement is already a feature.\n* Search to see if the enhancement has already been suggested (No need to open a new issue if its already there!).\n* See if your improvment fits the majority of users, if instead it adds minor functionality consider making a plugin library instead. \n* Describe the enchancement in detail, what does it actually do?\n\n### Improve Docs\nIf you'd like to improve the [documentation](#docs) please go over the following:\n\n* Read the [docs](#docs) first! If it's already there theres no point adding it.\n* Check issues for ideas, issues are a great place to find documentation to add or edit.\n* Provide examples for the area youre writing for (eg. showing a code example of how to use the `save` function)\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A simple python module for saving data to JSON files",
"version": "1.4.2",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "11ae0d977f80de0261b8ad62094e980905f4060485bc042f72ce5aed2609c25c",
"md5": "39099eebfba7f6a23e5a9361bfd2160f",
"sha256": "7267a6a81dddb32f43024a21b72f787c653d2fd3f9f1a2ce25e225931c17f595"
},
"downloads": -1,
"filename": "jsave-1.4.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "39099eebfba7f6a23e5a9361bfd2160f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 6753,
"upload_time": "2024-10-26T15:44:33",
"upload_time_iso_8601": "2024-10-26T15:44:33.858240Z",
"url": "https://files.pythonhosted.org/packages/11/ae/0d977f80de0261b8ad62094e980905f4060485bc042f72ce5aed2609c25c/jsave-1.4.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5ac054145cd33d17b992f3e91f8bb5818ee15ef3648135e069b28177ae1409f9",
"md5": "849151c7f110a6007803e94b3dafd4c8",
"sha256": "f3e7486d406231a6c1d0d70e8f19cec75c963f546180d5615977796430836bf5"
},
"downloads": -1,
"filename": "jsave-1.4.2.tar.gz",
"has_sig": false,
"md5_digest": "849151c7f110a6007803e94b3dafd4c8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 5453,
"upload_time": "2024-10-26T15:44:35",
"upload_time_iso_8601": "2024-10-26T15:44:35.055541Z",
"url": "https://files.pythonhosted.org/packages/5a/c0/54145cd33d17b992f3e91f8bb5818ee15ef3648135e069b28177ae1409f9/jsave-1.4.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-26 15:44:35",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "jsave"
}