Skip to main content

jq is a lightweight and flexible JSON processor.

Project description

This project contains Python bindings for jq.

Installation

During installation, the source for jq 1.4 is downloaded over HTTPS and built. Therefore, installation requires any programs required to build jq. This includes:

  • Autoreconf

  • The normal C compiler toolchain, such as gcc and make.

  • Flex

  • Bison

  • libtool

  • Python headers.

Debian, Ubuntu or relatives

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

apt-get install autoconf build-essential flex bison 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 flex bison 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 bison libtool

Note that at least some versions of Mac OS X ship a version of bison that is too old for jq to use. jq.py will try to use the version from Homebrew if available.

Usage

A program can be compiled by passing it to jq.jq. To apply the program to an input, call the transform method. jq.py expects the value to be valid JSON, such as values returned from json.load.

from jq import jq

jq(".").transform("42") == "42"
jq(".").transform({"a": 1}) == {"a": 1}

If the value is unparsed JSON text, pass it in using the text argument:

jq(".").transform(text="42") == 42

The text_output argument can be used to serialise the output into JSON text:

jq(".").transform("42", text_output=True) == '"42"'

If there are multiple output elements, each element is represented by a separate line, irrespective of the value of multiple_output:

jq(".[]").transform([1, 2, 3], text_output=True) == "1\n2\n3"

If multiple_output is False (the default), then the first output is used:

jq(".[]+1").transform([1, 2, 3]) == 2

If multiple_output is True, all output elements are returned in an array:

jq(".[]+1").transform([1, 2, 3], multiple_output=True) == [2, 3, 4]

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

jq-0.1.4.tar.gz (35.4 kB view details)

Uploaded Source

File details

Details for the file jq-0.1.4.tar.gz.

File metadata

  • Download URL: jq-0.1.4.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jq-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f090a910f54b68b53d2e25529f6660f3fd5fdb2fae68f5ffc62fd023573f56d5
MD5 3be49987665648b0232148aa55181bd0
BLAKE2b-256 6ea5b5e87cf3a7fb0e4b13190f2dd10441ddf44df427420ff48e85a2873ee76f

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