Skip to main content

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.2.tar.gz (2.1 kB view hashes)

Uploaded Source

Built Distribution

kokojson-0.1.2-py3-none-any.whl (2.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page