A module for safe JSON handling in Python
Project description
A module for safe JSON handling in Python
Example Usage:
data.json:
{
"person": {
"name": "John Doe",
"age": 30,
"city": "New York"
},
"company": {
"name": "Acme Inc.",
"employees": 500
}
}
import kokojson as json1
# Load the JSON data from the file
with open("data.json", "r") as file:
data = file.read()
# Parse the JSON data using kokojson
json_data = json1.load(data)
# Access existing keys
print(json_data.get("person").get("name")) # Output: John Doe
print(json_data.get("company").get("employees")) # Output: 500
# Access non-existing keys (returns None instead of raising an exception)
print(json_data.get("person").get("email")) # Output: None
print(json_data.get("company").get("website")) # Output: None
# Provide a default value for non-existing keys
print(json_data.get("person").get("email", "No email found")) # Output: No email found
print(json_data.get("company").get("website", "https://example.com")) # Output: https://example.com
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
kokojson-0.1.3.tar.gz
(2.3 kB
view details)
Built Distribution
File details
Details for the file kokojson-0.1.3.tar.gz
.
File metadata
- Download URL: kokojson-0.1.3.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53598c75a13a861f9e8d20a8b4950b653f0ef49957c0d314c7b576fe7c41d722 |
|
MD5 | fa5dce17cf6ca95a332f143783511341 |
|
BLAKE2b-256 | 8437a2c067b95edc895168ac4f09ba11dcace7c22975ff387d9d1604292e1a4b |
File details
Details for the file kokojson-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: kokojson-0.1.3-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6039880e73436f5365824640473c37e485d0a388139e9174eb35800a55102481 |
|
MD5 | 9493b67a92584e0da4742ed5dbe8befb |
|
BLAKE2b-256 | b4240e8a977db11c5f3501c91c4dd3bc12c3671162c211edfa6351599810a053 |