Skip to main content

A simple to use query api for json data

Project description

PyJsonQuery (pyjsonq)

PyJsonQ is an easy to use and package to query json data. It is a rewrite of the Go package "GoJSONQ" which you can find here: GoJSONQ Github Repository

I decided to rewrite this package in Python because I love it's simple API and is just a beauty to work with.

Future

Over time I will potentially update this package and add more fun and useful stuff to it, but for now the only thing I added are two operators for the Where method: holds, notHolds

Installation

pip install pyjsonquery

Usage

First import the JsonQuery class into your project

from pyjsonq import JsonQuery

Next create a new JsonQuery instance and load the data into the query using either File / file, String / string, TOMLFile / toml_file, TOMLString / toml_string or Raw / raw.

jq: JsonQuery = JsonQuery().String(
  """
  {
    "city": "dhaka",
    "type": "weekly",
    "temperatures": [
      30,
      39.9,
      35.4,
      33.5,
      31.6,
      33.2,
      30.7
    ]
  }
  """
)

# OR

jq: JsonQuery = JsonQuery().File("./file.json")

Once you created your query object you can then query over it using a variety of methods. Here is a quick example:

avg_temp: float = jq.At("temperatures").Avg()
print(avg_temp)  # 33.471428571428575

city_name: str = jq.Find("city")
print(city_name)  # dhaka

You can query over the json using various methods such as Find, First, Nth, Pluck, Where, OrWhere, WhereIn, Sort, SortBy, Drop, etc.

You can also aggregate your data after a query using Avg, Count, Max, Min, etc.

An overview over all query functions can be found in the wiki page

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

pyjsonquery-2.1.2.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

pyjsonquery-2.1.2-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file pyjsonquery-2.1.2.tar.gz.

File metadata

  • Download URL: pyjsonquery-2.1.2.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for pyjsonquery-2.1.2.tar.gz
Algorithm Hash digest
SHA256 49fa3f1f4a5c3aadb1a821a5b76aa5e85a9ce9e05f3f23bc0e6183df8f651f9f
MD5 4454610068fde32a964fbfba8f84651b
BLAKE2b-256 032c421a9f43ce9ad3856c41c108e39ca186f4120bd42ed89f56d5d1bca83e17

See more details on using hashes here.

File details

Details for the file pyjsonquery-2.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyjsonquery-2.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for pyjsonquery-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 13d1036b76cfb330fcdeebf3ecc8fb1bcddb1746b5869196d5a79c7dea69c13a
MD5 924f3888ef212eb141d8d4c0adb0b1ee
BLAKE2b-256 244b418e725c42b44cbc2a52643306e7c69bbee5f0d3734d603e27f44b2f5b27

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