A library dedicated to easy and seamless handling of JSON files
Project description
NanoJson library provided by Mohammed Ghanam.
NanoJson is a Python library designed to make working with JSON files easy and seamless. It offers a variety of functions to handle JSON data, such as reading, writing, modifying, and managing lists within JSON files, all with a simple and intuitive interface.
Features
- Reading JSON data: Easily read JSON data from a file.
- Writing JSON data: Write or update JSON data to a file.
- Updating JSON: Modify specific keys and values within a JSON file.
- Deleting keys: Remove specific keys from a JSON object.
- Search for keys: Search for and retrieve values associated with a specific key.
- Managing lists: Append or remove values from lists within JSON data.
Installation
To install NanoJson, use pip:
pip install NanoJson
Usage
First, you must import it:
import NanoJson
1) Reading JSON Data
You can read the contents of a JSON file and either print it as a formatted string or as a Python dictionary.
Example:
# Initialize the JSON helper with the path to your JSON file
json_helper = NanoJson("data.json")
Read the JSON data as a Python dictionary
data = json_helper.read_json()
Print the formatted JSON data
formatted_data = json_helper.read_json(pretty=True)
2) Writing JSON Data
You can write new JSON data or update existing data in a file.
Example:
# New data to write to the file
new_data = {"name": "John", "age": 30}
# Write the new data to the JSON file
json_helper.write_json(new_data)
3) Updating JSON Data
You can update a specific key with a new value in your JSON data.
Example:
# Update the value of the "age" key
json_helper.update_json("age", 31)
4) Deleting Keys
You can delete a key from your JSON file.
Example:
# Remove the key "name" from the JSON data
json_helper.delete_key("name")
5) Searching for a Key
You can search for a specific key in the JSON data and retrieve its value.
Example:
# Get the value associated with the key "age"
age = json_helper.search_key("age")
6) Managing Lists
You can append or remove items from lists stored within your JSON file.
Example:
# Append a new item to the list under the "items" key
json_helper.append_to_list("items", "new_item")
# Remove an item from the list under the "items" key
json_helper.remove_from_list("items", "old_item")
For Contact:
- My telegram Account: @midoghanam
- My Channel: @mido_ghanam
Best Regards ♡
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nanojson-1.0.tar.gz.
File metadata
- Download URL: nanojson-1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98c0183bc6589b3bf40e95f9b14b5eb6b586a39e4fffede8ac2ae786313b44da
|
|
| MD5 |
8b57ea0775a42952554d2561d0b8e2a1
|
|
| BLAKE2b-256 |
a314bacb5091e5bdee7600a6f7a0915ea2698649724b1a26bd7585963cf91051
|
File details
Details for the file nanojson-1.0-py3-none-any.whl.
File metadata
- Download URL: nanojson-1.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e4c3ee599114ef2e52318fe24f2a8cf5f6d3aee1b9c51c788ff82f16b8b1d0e
|
|
| MD5 |
d197b24dfc16823b3db0aabb6e737c03
|
|
| BLAKE2b-256 |
4a15872bfb768a6a9b135785ae7cf98f0ece2b19ce5c4ea890b489871d69d4f5
|