Skip to main content

Handle JSON files easily, like in JavaScript

Project description

Handle JSON objects more simply, like you do in JavaScript.

This Python module provides an interface to JSON data structures that is more reminiscent of the compact and forgiving syntax that you use in JavaScript than the verbose and picky Python 'dict' interface.

For example, instead of:

from pathlib import Path
import json

with Path('data.json').open(encoding='utf-8') as fh:
    data = json.load(fh)
version = (data.get('summary') or {}).get('version')

you can write:

from pathlib import Path
from opchjson import JSON

data = JSON.parse(Path('data.json'))
version = data.summary.version

i.e. you can access object properties using the . operator, just like in JavaScript. If you access a non-existent property, it will return JSON.undefined. Note that one difference from JavaScript behaviour is that if you try and retrieve properties from undefined it will return undefined rather than throwing an exception.

Note that you cannot access object properties that start with an underscore character via the . operator, as this is reserved for accessing Python dictionary methods - e.g. data._items(). If you want to access a property that begins with _, simply use the standard Python [] operator- e.g. data['_foo']. This will similarly return JSON.undefined if the property does not exist.

History

0.1.0 (2026-06-02)

  • Initial version.

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

opchjson-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opchjson-0.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file opchjson-0.1.0.tar.gz.

File metadata

  • Download URL: opchjson-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for opchjson-0.1.0.tar.gz
Algorithm Hash digest
SHA256 38c51ac4ad22a1347ab92f865692b00e611f89d1dfada161b0634b9cb8b77485
MD5 886c89a62c8f19e826c6bb901ecbea36
BLAKE2b-256 27522643375fcd79e9e7324fe9c7f03657a9cbaca172fbed03c6143d7d58df00

See more details on using hashes here.

File details

Details for the file opchjson-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: opchjson-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for opchjson-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a7eea2af6dc677fa48d33e49134d024ecf165dedf90ea75e5fb30f07fe38a69
MD5 a1bff7e6b4dbda755a808944bd1e50f6
BLAKE2b-256 247b20680bd4d014376e337315847fadab51a1691b3eeb2d0ff1969f2cfdf8df

See more details on using hashes here.

Supported by

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