# jsondatasave
## Overview
jsondatasave is a Python library that provides a set of functions to facilitate working with JSON data. It includes functionalities to load, save, append, update, and delete data in JSON files, as well as support for custom encoders and decoders. The aim is to simplify common tasks associated with JSON data management while handling potential errors gracefully.
## Installation
To use this library, simply include it in your Python project. No additional installation steps are required.
## Functions
### `load(FileName: str) -> Any`
Loads data from a JSON file.
- **Parameters:**
- `FileName`: The name of the file to load.
- **Returns:**
- The data loaded from the JSON file.
- **Exceptions:**
- Prints an error message if the file does not exist or contains invalid JSON.
### `save(Data: Any, Filename: str, pretty: bool = False, encoder: Optional[json.JSONEncoder] = None) -> Any`
Saves data to a JSON file.
- **Parameters:**
- `Data`: The data to save.
- `Filename`: The name of the file to save the data to.
- `pretty`: If `True`, the JSON is pretty-printed with an indentation of 4 spaces. Default is `False`.
- `encoder`: Optional custom JSON encoder.
- **Returns:**
- The saved data.
- **Exceptions:**
- Prints an error message if an unexpected error occurs during the save operation.
### `append(Data: Any, Filename: str, encoder: Optional[json.JSONEncoder] = None) -> Any`
Appends data to an existing JSON file containing a JSON array.
- **Parameters:**
- `Data`: The data to append.
- `Filename`: The name of the file to append the data to.
- `encoder`: Optional custom JSON encoder.
- **Returns:**
- The updated data.
- **Exceptions:**
- Prints an error message if the file does not contain a JSON array or if an unexpected error occurs.
### `load_with_decoder(FileName: str, decoder: Optional[json.JSONDecoder] = None) -> Any`
Loads data from a JSON file using a custom decoder.
- **Parameters:**
- `FileName`: The name of the file to load.
- `decoder`: Optional custom JSON decoder.
- **Returns:**
- The data loaded from the JSON file.
- **Exceptions:**
- Prints an error message if the file does not exist or contains invalid JSON.
### `update(Filename: str, key: str, value: Any, encoder: Optional[json.JSONEncoder] = None) -> Any`
Updates a specific key in a JSON file.
- **Parameters:**
- `Filename`: The name of the file to update.
- `key`: The key to update.
- `value`: The new value for the key.
- `encoder`: Optional custom JSON encoder.
- **Returns:**
- The updated data.
- **Exceptions:**
- Prints an error message if the file does not contain a JSON object or if an unexpected error occurs.
### `delete(Filename: str, key: str, encoder: Optional[json.JSONEncoder] = None) -> Any`
Deletes a specific key from a JSON file.
- **Parameters:**
- `Filename`: The name of the file to update.
- `key`: The key to delete.
- `encoder`: Optional custom JSON encoder.
- **Returns:**
- The updated data.
- **Exceptions:**
- Prints an error message if the file does not contain a JSON object, the key does not exist, or if an unexpected error occurs.
## Error Handling
The library handles common errors such as file not found, invalid JSON format, and unexpected exceptions. Error messages are printed to the console to inform the user of the issue.
## Examples
### Loading a JSON File
```python
data = load('data.json')
```
### Saving Data to a JSON File
```python
save(data, 'data.json', pretty=True)
```
### Appending Data to a JSON File
```python
append(new_data, 'data.json')
```
### Loading a JSON File with a Custom Decoder
```python
data = load_with_decoder('data.json', decoder=CustomDecoder)
```
### Updating a Key in a JSON File
```python
update('data.json', 'key_to_update', new_value)
```
### Deleting a Key from a JSON File
```python
delete('data.json', 'key_to_delete')
```
## License
This library is provided as-is, without warranty of any kind. Use at your own risk.
Raw data
{
"_id": null,
"home_page": "https://github.com/SimplyYourAverageDev/jsondatasave",
"name": "jsondatasave",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "python, JSON, Data Storage",
"author": "YourAverageDev",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/36/e2/1483e8716ca5d3192d037835e717056499b54c8490d6e64ed77527799eaa/jsondatasave-1.6.1.tar.gz",
"platform": null,
"description": "# jsondatasave\n\n## Overview\n\njsondatasave is a Python library that provides a set of functions to facilitate working with JSON data. It includes functionalities to load, save, append, update, and delete data in JSON files, as well as support for custom encoders and decoders. The aim is to simplify common tasks associated with JSON data management while handling potential errors gracefully.\n\n## Installation\n\nTo use this library, simply include it in your Python project. No additional installation steps are required.\n\n## Functions\n\n### `load(FileName: str) -> Any`\n\nLoads data from a JSON file.\n\n- **Parameters:**\n - `FileName`: The name of the file to load.\n \n- **Returns:**\n - The data loaded from the JSON file.\n \n- **Exceptions:**\n - Prints an error message if the file does not exist or contains invalid JSON.\n\n### `save(Data: Any, Filename: str, pretty: bool = False, encoder: Optional[json.JSONEncoder] = None) -> Any`\n\nSaves data to a JSON file.\n\n- **Parameters:**\n - `Data`: The data to save.\n - `Filename`: The name of the file to save the data to.\n - `pretty`: If `True`, the JSON is pretty-printed with an indentation of 4 spaces. Default is `False`.\n - `encoder`: Optional custom JSON encoder.\n \n- **Returns:**\n - The saved data.\n \n- **Exceptions:**\n - Prints an error message if an unexpected error occurs during the save operation.\n\n### `append(Data: Any, Filename: str, encoder: Optional[json.JSONEncoder] = None) -> Any`\n\nAppends data to an existing JSON file containing a JSON array.\n\n- **Parameters:**\n - `Data`: The data to append.\n - `Filename`: The name of the file to append the data to.\n - `encoder`: Optional custom JSON encoder.\n \n- **Returns:**\n - The updated data.\n \n- **Exceptions:**\n - Prints an error message if the file does not contain a JSON array or if an unexpected error occurs.\n\n### `load_with_decoder(FileName: str, decoder: Optional[json.JSONDecoder] = None) -> Any`\n\nLoads data from a JSON file using a custom decoder.\n\n- **Parameters:**\n - `FileName`: The name of the file to load.\n - `decoder`: Optional custom JSON decoder.\n \n- **Returns:**\n - The data loaded from the JSON file.\n \n- **Exceptions:**\n - Prints an error message if the file does not exist or contains invalid JSON.\n\n### `update(Filename: str, key: str, value: Any, encoder: Optional[json.JSONEncoder] = None) -> Any`\n\nUpdates a specific key in a JSON file.\n\n- **Parameters:**\n - `Filename`: The name of the file to update.\n - `key`: The key to update.\n - `value`: The new value for the key.\n - `encoder`: Optional custom JSON encoder.\n \n- **Returns:**\n - The updated data.\n \n- **Exceptions:**\n - Prints an error message if the file does not contain a JSON object or if an unexpected error occurs.\n\n### `delete(Filename: str, key: str, encoder: Optional[json.JSONEncoder] = None) -> Any`\n\nDeletes a specific key from a JSON file.\n\n- **Parameters:**\n - `Filename`: The name of the file to update.\n - `key`: The key to delete.\n - `encoder`: Optional custom JSON encoder.\n \n- **Returns:**\n - The updated data.\n \n- **Exceptions:**\n - Prints an error message if the file does not contain a JSON object, the key does not exist, or if an unexpected error occurs.\n\n## Error Handling\n\nThe library handles common errors such as file not found, invalid JSON format, and unexpected exceptions. Error messages are printed to the console to inform the user of the issue.\n\n## Examples\n\n### Loading a JSON File\n\n```python\ndata = load('data.json')\n```\n\n### Saving Data to a JSON File\n\n```python\nsave(data, 'data.json', pretty=True)\n```\n\n### Appending Data to a JSON File\n\n```python\nappend(new_data, 'data.json')\n```\n\n### Loading a JSON File with a Custom Decoder\n\n```python\ndata = load_with_decoder('data.json', decoder=CustomDecoder)\n```\n\n### Updating a Key in a JSON File\n\n```python\nupdate('data.json', 'key_to_update', new_value)\n```\n\n### Deleting a Key from a JSON File\n\n```python\ndelete('data.json', 'key_to_delete')\n```\n\n## License\n\nThis library is provided as-is, without warranty of any kind. Use at your own risk.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Facilitating the process to store JSON data",
"version": "1.6.1",
"project_urls": {
"Bug Tracker": "https://github.com/SimplyYourAverageDev/jsondatasave/issues",
"Documentation": "https://github.com/SimplyYourAverageDev/jsondatasave#readme",
"Homepage": "https://github.com/SimplyYourAverageDev/jsondatasave"
},
"split_keywords": [
"python",
" json",
" data storage"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a44ef7f089631bdaf2688b7132bdf1dffbe9bae345a4c6d3ce61f23461202a20",
"md5": "625d975034a1c1af165a3bf3968433ff",
"sha256": "e91c4296b0b1b5c4ab0f47efb5de423736147bbbdd94e85ff596d44f289ba807"
},
"downloads": -1,
"filename": "jsondatasave-1.6.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "625d975034a1c1af165a3bf3968433ff",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 2849,
"upload_time": "2024-06-09T01:52:13",
"upload_time_iso_8601": "2024-06-09T01:52:13.492639Z",
"url": "https://files.pythonhosted.org/packages/a4/4e/f7f089631bdaf2688b7132bdf1dffbe9bae345a4c6d3ce61f23461202a20/jsondatasave-1.6.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "36e21483e8716ca5d3192d037835e717056499b54c8490d6e64ed77527799eaa",
"md5": "076b96854b93204eedc86f804851fac8",
"sha256": "c9a509c90276d2771247345c09abb6249e92a101663db24ebf34974936fdf4cb"
},
"downloads": -1,
"filename": "jsondatasave-1.6.1.tar.gz",
"has_sig": false,
"md5_digest": "076b96854b93204eedc86f804851fac8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3023,
"upload_time": "2024-06-09T01:52:14",
"upload_time_iso_8601": "2024-06-09T01:52:14.446904Z",
"url": "https://files.pythonhosted.org/packages/36/e2/1483e8716ca5d3192d037835e717056499b54c8490d6e64ed77527799eaa/jsondatasave-1.6.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-09 01:52:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SimplyYourAverageDev",
"github_project": "jsondatasave",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "jsondatasave"
}