jq (Python bindings)

1.11.0 · active · verified Thu Apr 09

jq is a lightweight and flexible JSON processor. This Python library provides robust bindings to the native `jq` C library (version 1.8.1), allowing Python applications to compile and execute `jq` programs for efficient JSON manipulation, filtering, and transformation. Currently at version 1.11.0, the project maintains an active release cadence with regular updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates compiling a `jq` program and applying it to both single JSON values and lists of values using the recommended `input_value()` and `input_values()` methods. It then retrieves the first or all results.

import jq

json_data = {"name": "Alice", "age": 30, "city": "New York"}

# Compile a jq program to extract the name and add a greeting
compiled_program = jq.compile(".name | ""Hello, \(. )!""")

# Process a single JSON value
result = compiled_program.input_value(json_data).first()
print(result)

# Example with a list of values
list_data = [{"value": 1}, {"value": 2}]
compiled_list_program = jq.compile(".value + 10")
results_list = compiled_list_program.input_values(list_data).all()
print(results_list)

view raw JSON →