Skip to main content

Python bindings for gjson.rs - fast JSON path queries

Project description

pygjson

PyGJSON is a Python bindings for tidwall/gjson.rs.

The original GJSON: https://github.com/tidwall/gjson

Installation

pip install pygjson

Quick example

import pygjson

JSON = """{
  "name": {"first": "Tom", "last": "Anderson"},
  "age": 37,
  "children": ["Sara", "Alex", "Jack"],
  "friends": [
    {"first": "Dale",  "last": "Murphy", "age": 44},
    {"first": "Roger", "last": "Craig",  "age": 68},
    {"first": "Jane",  "last": "Murphy", "age": 47}
  ]
}"""

str(pygjson.get(JSON, "name.last"))                           # 'Anderson'
int(pygjson.get(JSON, "age"))                                 # 37
int(pygjson.get(JSON, "children.#"))                         # 3
str(pygjson.get(JSON, "children.1"))                          # 'Alex'
str(pygjson.get(JSON, 'friends.#(last="Murphy").first'))      # 'Dale'

[str(v) for v in pygjson.get(JSON, "children|@reverse")]
# ['Jack', 'Alex', 'Sara']

pygjson.valid(JSON)  # True

API

Module-level functions

Function Description
get(json, path) Query json at path; returns Value (gjson-native)
get(json, path, default) Returns default if path is not found (Pythonic)
parse(json) Parse the entire JSON document into a Value
valid(json) True if json is syntactically valid

Value

get and parse return a Value. The API is split into two layers:

gjson-native methods — mirror the Rust gjson::Value API directly:

Method Description
v.kind() Returns a Kind enum value
v.exists() True if the value was actually found in the JSON
v.to_str() String representation (gjson str behaviour)
v.to_int() Signed 64-bit integer (i64)
v.to_uint() Unsigned 64-bit integer (u64)
v.to_float() 64-bit float
v.to_bool() True only for the JSON literal true
v.json() Raw JSON text for this value
v.get(path) Sub-query relative to this value (gjson-native)
v.get(path, default) Sub-query; returns default if not found (Pythonic)
v.to_list() list[Value] for arrays
v.to_dict() dict[str, Value] for objects

Pythonic methods — follow standard Python protocols:

Syntax Description
str(v) String representation
int(v) Integer (negative → i64, non-negative → u64)
float(v) 64-bit float
bool(v) True if v.exists()
len(v) Chars for String; element count for Array/Object
v[key] Subscript access for Object values
key in v Key membership for Object; str match for Array elements
iter(v) Chars for String; Values for Array; keys for Object
v.keys() Object keys (raises TypeError for non-Object)
v.values() Object values (raises TypeError for non-Object)
v.items() (key, Value) pairs (raises TypeError for non-Object)

Kind

from pygjson import Kind
Kind.Null   Kind.False_   Kind.True_   Kind.Number
Kind.String Kind.Array    Kind.Object

(False and True are Python keywords, so the variants are named with a trailing underscore.)

Usage examples

from pygjson import get, parse, valid, Kind

# gjson-native: missing value returns Value(exists=False)
v = get(JSON, "no.such.path")
v.exists()   # False
bool(v)      # False

# Pythonic: missing value returns None (or a custom default)
get(JSON, "no.such.path", None)   # None
get(JSON, "no.such.path", 42)     # 42

# Type conversion
age = get(JSON, "age")
age.to_int()    # gjson i64 behaviour
int(age)        # Python int protocol

# Boolean distinction
get('{"flag": true}', "flag").to_bool()    # True  (JSON true literal)
bool(get(JSON, "age"))                     # True  (value exists)

# Array iteration
children = get(JSON, "children")
list(children)                  # [Value("Sara"), Value("Alex"), Value("Jack")]
[str(v) for v in children]      # ['Sara', 'Alex', 'Jack']
"Sara" in children              # True

# Object (dict-like) access
name = get(JSON, "name")
name["first"]                   # Value("Tom")
"first" in name                 # True
list(name)                      # ['first', 'last']  — keys
dict(name)                      # {'first': Value("Tom"), 'last': Value("Anderson")}
for k, v in name.items():
    print(k, str(v))

# Chained queries
parse(JSON).get("name").get("first")   # Value("Tom")

Path syntax

For the full path / query / modifier syntax see the upstream gjson.rs and the original GJSON path syntax.

License

MIT

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

pygjson-0.0.1.tar.gz (11.6 kB view details)

Uploaded Source

Built Distributions

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

pygjson-0.0.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (342.5 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

pygjson-0.0.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (342.9 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

pygjson-0.0.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (343.0 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

pygjson-0.0.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (346.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

pygjson-0.0.1-cp310-abi3-win_arm64.whl (196.7 kB view details)

Uploaded CPython 3.10+Windows ARM64

pygjson-0.0.1-cp310-abi3-win_amd64.whl (205.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

pygjson-0.0.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (342.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

pygjson-0.0.1-cp310-abi3-macosx_11_0_arm64.whl (305.9 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

pygjson-0.0.1-cp310-abi3-macosx_10_12_x86_64.whl (310.1 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

pygjson-0.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (349.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file pygjson-0.0.1.tar.gz.

File metadata

  • Download URL: pygjson-0.0.1.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pygjson-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b38689d575176906673e75dfe8fe2b97a0f1fa328dd455c0b230ca9d3cd3a15b
MD5 c8a568007717fa8f6846768a038466c0
BLAKE2b-256 1af96f19bfc9f6128b9971245316ad2ee0c962767d25991747c5ac90eafc1bd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygjson-0.0.1.tar.gz:

Publisher: publish.yml on minefuto/pygjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygjson-0.0.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pygjson-0.0.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2f46b7e3203c41b17c86eeb6282c692290f3a3a93925778671c0a04c3bf7f0d4
MD5 d96c5ed902bff0b2b1d402d3a2213740
BLAKE2b-256 62edfdc2f0f702842c699bdcfb5b53cd467ed128717de016ce01f2d5955a7aa9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygjson-0.0.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on minefuto/pygjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygjson-0.0.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pygjson-0.0.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c84b7ba7a50c81eab146c0a7f378fbce05f5cdd42f7c6b5119f30be755e33913
MD5 0185d7d5bf8cb5cad31f7677b717be35
BLAKE2b-256 0b465295e51ce3a768fa0e94c36759dceee895af23a2cd338f2101df829bc189

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygjson-0.0.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on minefuto/pygjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygjson-0.0.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pygjson-0.0.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 47869017b9008eeaede7f28d19856e4f7427940da67c157d00a15951ae6297c1
MD5 4bd81ebe846a9cb3ff90565b692281a2
BLAKE2b-256 b11dd977dcf81313b998fabc9246fd846e4eb2e52782bc52eed662941ebb80d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygjson-0.0.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on minefuto/pygjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygjson-0.0.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pygjson-0.0.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 57102e0a41121d1d1294020ed63bc0b4cb7e3a9948f437b3459a8728239a0388
MD5 a22e5e5b14e94e6cf1cb772db6d3520f
BLAKE2b-256 abe6cdde4eaf76b65916f2f37fec5187fe7cb9583fc6776723084722c6176a50

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygjson-0.0.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on minefuto/pygjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygjson-0.0.1-cp310-abi3-win_arm64.whl.

File metadata

  • Download URL: pygjson-0.0.1-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 196.7 kB
  • Tags: CPython 3.10+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pygjson-0.0.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 3bb7f8f1b8c835bd4a990c5b788bb64a534df600c919d713654fc7f513fb80bd
MD5 622963978288ea2dddb828e2cba32e0c
BLAKE2b-256 f552394a6a62a0da73c8042a38357b051f8a7678220a42095b303198909dfdc1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygjson-0.0.1-cp310-abi3-win_arm64.whl:

Publisher: publish.yml on minefuto/pygjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygjson-0.0.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: pygjson-0.0.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 205.7 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pygjson-0.0.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f62d76b3030a2850471f1d924450767383d386f9b96c3dce9841410ca458ff2b
MD5 a464b1502d8171f29e673f4797dcd3fd
BLAKE2b-256 ad589d753cc92ce8f5499fa5c9b038726b5575491048ecbda1d904e4d590be72

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygjson-0.0.1-cp310-abi3-win_amd64.whl:

Publisher: publish.yml on minefuto/pygjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygjson-0.0.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pygjson-0.0.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b2eabba315a3ebb03f76b33e0ba65508bb1014d274b20083cd8a5a5721eb01a6
MD5 d202878c325537e2a6f7fcff0d7c6b0a
BLAKE2b-256 5d983add2a1f5e895eeb82b28d6fdd4d8a06da9968906ea860d2563e861fb256

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygjson-0.0.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on minefuto/pygjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygjson-0.0.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pygjson-0.0.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e757ac4e6f3ffa613d486324453ce0b5a8aaa40c58c922e4cef8d2a8c1234711
MD5 7e93a96b641d5a3f9fe1424aabc6cf83
BLAKE2b-256 c54f359986b548952ab255537c9308f6d662be683cab024f5f21b7458fb796a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygjson-0.0.1-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on minefuto/pygjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygjson-0.0.1-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pygjson-0.0.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cccc1905237abdaeab9b69a945479b9450426029287db397503ef0df3155ecca
MD5 406f6f196327e993fa8161cd11bcb5e8
BLAKE2b-256 a55dd42f344677ad6b28791cf19429bf9e33c2b4ce7bbd0320ba72fb8d48fd47

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygjson-0.0.1-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: publish.yml on minefuto/pygjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygjson-0.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pygjson-0.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ac12cb6212ecc3962aa36289c8dbae442c277913f9d10fb546503d2488c5b7ef
MD5 d70ec1292765909262599f126a719fbe
BLAKE2b-256 da774c6e049c4140580f5a64ded41cd46915492529ebfdb470947cce205926ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygjson-0.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on minefuto/pygjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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