Skip to main content

gjson-py is a Python package that provides a simple way to filter and extract data from JSON-like objects or JSON files, using the GJSON syntax.

Project description

Introduction

gjson-py is a Python package that provides a simple way to filter and extract data from JSON-like objects or JSON files, using the GJSON syntax.

It is, compatibly with the language differences and with some limitation, the Python equivalent of the Go GJSON package. The main difference from GJSON is that gjson-py doesn’t work directly with JSON strings but instead with JSON-like Python objects, that can either be the resulting object when calling json.load() or json.loads(), or any Python object that is JSON-serializable.

A detailed list of the GJSON features supported by gjson-py is provided below.

Installation

gjson-py is available on the Python Package Index (PyPI) and can be easily installed with:

pip install gjson

How to use the library

gjson-py provides different ways to perform queries on JSON-like objects.

gjson.get()

A quick accessor to GJSON functionalities exposed for simplicity of use. Particularly useful to perform a single query on a given object:

>>> import gjson
>>> data = {'name': {'first': 'Tom', 'last': 'Anderson'}, 'age': 37}
>>> gjson.get(data, 'name.first')
'Tom'

It’s also possible to make it return a JSON-encoded string and decide on failure if it should raise an exception or return None. See the full API documentation for more details.

GJSON class

The GJSON class provides full access to the gjson-py API allowing to perform multiple queries on the same object:

>>> import gjson
>>> data = {'name': {'first': 'Tom', 'last': 'Anderson'}, 'age': 37}
>>> source = gjson.GJSON(data)
>>> source.get('name.first')
'Tom'
>>> str(source)
'{"name": {"first": "Tom", "last": "Anderson"}, "age": 37}'
>>> source.getj('name.first')
'"Tom"'
>>> name = source.get_gjson('name')
>>> name.get('first')
'Tom'
>>> name
<gjson.GJSON object at 0x102735b20>

See the full API documentation for more details.

Query syntax

For the generic query syntax refer to the original GJSON Path Syntax documentation.

Supported GJSON features

This is the list of GJSON features and how they are supported by gjson-py:

GJSON feature

Supported by gjson-py

Notes

Path Structure

YES

Basic

YES

Wildcards

YES

Escape Character

YES

Arrays

YES

Queries

PARTIALLY

Subqueries and the tilde operator are not supported

Dot vs Pipe

YES

Modifiers

PARTIALLY

See the table below

Modifier arguments

YES

Custom modifier

NO

Multipaths

NO

Literals

NO

This is the list of GJSON modifiers and how they are supported by gjson-py:

GJSON Modifier

Supported by gjson-py

Notes

@reverse

YES

@ugly

YES

@pretty

PARTIALLY

The width argument is not supported

@this

NO

@valid

YES

@flatten

YES

@join

NO

@keys

YES

@values

YES

@tostr

NO

@fromstr

NO

@group

NO

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

gjson-0.0.1.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

gjson-0.0.1-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gjson-0.0.1.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for gjson-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fc980da8e2486d309fd5cd66fd3f8ba806b148212ecee9f6c253b45817c27e44
MD5 d1874b82d1524957a9f17fbc1e154021
BLAKE2b-256 73692a45b3543fe40388f506ab9ce590e069348c6cafdc865bb66297369b9c03

See more details on using hashes here.

File details

Details for the file gjson-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: gjson-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for gjson-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f44a6849a291d048571327b2423e0d703b1e245559cce0ff9dd16db4b607785e
MD5 5a62361f7ba8c81aa393433951eccf6d
BLAKE2b-256 73361664f5b30db73d6d299c22d5aae169ee1407c141dadb2ec59354302afc71

See more details on using hashes here.

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