Skip to main content

jq is a lightweight and flexible JSON processor.

Project description

This project contains Python bindings for jq.

Installation

Wheels are built for various Python versions and architectures on Linux and Mac OS X. On these platforms, you should be able to install jq with a normal pip install:

pip install jq

If a wheel is not available, the source for jq 1.6 is downloaded over HTTPS and built. This requires:

  • Autoreconf
  • The normal C compiler toolchain, such as gcc and make.
  • libtool
  • Python headers.

Debian, Ubuntu or relatives

If on Debian, Ubuntu or relatives, running the following command should be sufficient:

apt-get install autoconf automake build-essential libtool python-dev

Red Hat, Fedora, CentOS or relatives

If on Red Hat, Fedora, CentOS, or relatives, running the following command should be sufficient:

yum groupinstall "Development Tools"
yum install autoconf automake libtool python

Mac OS X

If on Mac OS X, you probably want to install Xcode and Homebrew. Once Homebrew is installed, you can install the remaining dependencies with:

brew install autoconf automake libtool

Usage

Call jq.compile to compile a jq program. Call .input() on the compiled program to supply an input value. The input must either be:

  • a valid JSON value, such as the values returned from json.load
  • unparsed JSON text passed as the keyword argument text.

Calling first() on the result will run the program with the given input, and return the first output element.

import jq

assert jq.compile(".").input("hello").first() == "hello"
assert jq.compile(".").input(text='"hello"').first() == "hello"
assert jq.compile("[.[]+1]").input([1, 2, 3]).first() == [2, 3, 4]
assert jq.compile(".[]+1").input([1, 2, 3]).first() == 2

Call text() instead of first() to serialise the output into JSON text:

assert jq.compile(".").input("42").text() == '"42"'

When calling text(), if there are multiple output elements, each element is represented by a separate line:

assert jq.compile(".[]").input([1, 2, 3]).text() == "1\n2\n3"

Call all() to get all of the output elements in a list:

assert jq.compile(".[]+1").input([1, 2, 3]).all() == [2, 3, 4]

Call iter() to get all of the output elements as an iterator:

iterator = iter(jq.compile(".[]+1").input([1, 2, 3]))
assert next(iterator, None) == 2
assert next(iterator, None) == 3
assert next(iterator, None) == 4
assert next(iterator, None) == None

Convenience functions are available to get the output for a program and input in one call:

assert jq.first(".[] + 1", [1, 2, 3]) == 2
assert jq.first(".[] + 1", text="[1, 2, 3]") == 2
assert jq.text(".[] + 1", [1, 2, 3]) == "2\n3\n4"
assert jq.all(".[] + 1", [1, 2, 3]) == [2, 3, 4]
assert list(jq.iter(".[] + 1", [1, 2, 3])) == [2, 3, 4]

The original program string is available on a compiled program as the program_string attribute:

program = jq.compile(".")
assert program.program_string == "."

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for jq, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size jq-1.0.2-cp27-cp27m-macosx_10_9_x86_64.whl (367.1 kB) File type Wheel Python version cp27 Upload date Hashes View
Filename, size jq-1.0.2-cp27-cp27m-manylinux1_i686.whl (475.0 kB) File type Wheel Python version cp27 Upload date Hashes View
Filename, size jq-1.0.2-cp27-cp27m-manylinux1_x86_64.whl (475.7 kB) File type Wheel Python version cp27 Upload date Hashes View
Filename, size jq-1.0.2-cp27-cp27m-manylinux2010_i686.whl (475.0 kB) File type Wheel Python version cp27 Upload date Hashes View
Filename, size jq-1.0.2-cp27-cp27m-manylinux2010_x86_64.whl (475.7 kB) File type Wheel Python version cp27 Upload date Hashes View
Filename, size jq-1.0.2-cp27-cp27mu-manylinux1_i686.whl (475.0 kB) File type Wheel Python version cp27 Upload date Hashes View
Filename, size jq-1.0.2-cp27-cp27mu-manylinux1_x86_64.whl (475.6 kB) File type Wheel Python version cp27 Upload date Hashes View
Filename, size jq-1.0.2-cp27-cp27mu-manylinux2010_i686.whl (475.0 kB) File type Wheel Python version cp27 Upload date Hashes View
Filename, size jq-1.0.2-cp27-cp27mu-manylinux2010_x86_64.whl (475.7 kB) File type Wheel Python version cp27 Upload date Hashes View
Filename, size jq-1.0.2-cp35-cp35m-macosx_10_9_x86_64.whl (375.0 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size jq-1.0.2-cp35-cp35m-manylinux1_i686.whl (496.4 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size jq-1.0.2-cp35-cp35m-manylinux1_x86_64.whl (495.8 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size jq-1.0.2-cp35-cp35m-manylinux2010_i686.whl (496.4 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size jq-1.0.2-cp35-cp35m-manylinux2010_x86_64.whl (495.8 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size jq-1.0.2-cp36-cp36m-macosx_10_9_x86_64.whl (369.2 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size jq-1.0.2-cp36-cp36m-manylinux1_i686.whl (502.7 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size jq-1.0.2-cp36-cp36m-manylinux1_x86_64.whl (502.4 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size jq-1.0.2-cp36-cp36m-manylinux2010_i686.whl (502.7 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size jq-1.0.2-cp36-cp36m-manylinux2010_x86_64.whl (502.4 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size jq-1.0.2-cp37-cp37m-macosx_10_9_x86_64.whl (366.7 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size jq-1.0.2-cp37-cp37m-manylinux1_i686.whl (502.3 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size jq-1.0.2-cp37-cp37m-manylinux1_x86_64.whl (502.2 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size jq-1.0.2-cp37-cp37m-manylinux2010_i686.whl (502.3 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size jq-1.0.2-cp37-cp37m-manylinux2010_x86_64.whl (502.2 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size jq-1.0.2-cp38-cp38-macosx_10_9_x86_64.whl (368.2 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size jq-1.0.2-cp38-cp38-manylinux1_i686.whl (530.4 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size jq-1.0.2-cp38-cp38-manylinux1_x86_64.whl (532.8 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size jq-1.0.2-cp38-cp38-manylinux2010_i686.whl (530.4 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size jq-1.0.2-cp38-cp38-manylinux2010_x86_64.whl (532.8 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size jq-1.0.2-pp27-pypy_73-macosx_10_7_x86_64.whl (364.8 kB) File type Wheel Python version pp27 Upload date Hashes View
Filename, size jq-1.0.2-pp27-pypy_73-manylinux1_x86_64.whl (362.9 kB) File type Wheel Python version pp27 Upload date Hashes View
Filename, size jq-1.0.2-pp27-pypy_73-manylinux2010_x86_64.whl (362.9 kB) File type Wheel Python version pp27 Upload date Hashes View
Filename, size jq-1.0.2-pp36-pypy36_pp73-macosx_10_7_x86_64.whl (364.8 kB) File type Wheel Python version pp36 Upload date Hashes View
Filename, size jq-1.0.2-pp36-pypy36_pp73-manylinux1_x86_64.whl (363.1 kB) File type Wheel Python version pp36 Upload date Hashes View
Filename, size jq-1.0.2-pp36-pypy36_pp73-manylinux2010_x86_64.whl (363.1 kB) File type Wheel Python version pp36 Upload date Hashes View
Filename, size jq-1.0.2.tar.gz (57.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page