Command-line JSON processor

jq

jq is a lightweight and flexible command-line JSON processor.

Coverage Status, Unix: Build Status, Windows: Windows build status

If you want to learn to use jq, read the documentation at https://stedolan.github.io/jq. This documentation is generated from the docs/ folder of this repository. You can also try it online at jqplay.org.

If you want to hack on jq, feel free, but be warned that its internals are not well-documented at the moment. Bring a hard hat and a shovel. Also, read the wiki: https://github.com/stedolan/jq/wiki, where you will find cookbooks, discussion of advanced topics, internals, release engineering, and more.

Source tarball and built executable releases can be found on the homepage and on the github release page, https://github.com/stedolan/jq/releases

If you're building directly from the latest git, you'll need flex, bison (3.0 or newer), libtool, make, automake, and autoconf installed. To get regexp support you'll also need to install Oniguruma or clone it as a git submodule as per the instructions below. (note that jq's tests require regexp support to pass). To build, run:

git submodule update --init # if building from git to get oniguruma
autoreconf -fi              # if building from git
./configure --with-oniguruma=builtin
make -j8
make check

To build without bison or flex, add --disable-maintainer-mode to the ./configure invocation:

./configure --with-oniguruma=builtin --disable-maintainer-mode

(Developers must not use --disable-maintainer-mode, not when making changes to the jq parser and/or lexer.)

To build a statically linked version of jq, run:

make LDFLAGS=-all-static

After make finishes, you'll be able to use ./jq. You can also install it using:

sudo make install

If you're not using the latest git version but instead building a released tarball (available on the website), then you won't need to run autoreconf (and shouldn't), and you won't need flex or bison.

To cross-compile for OS X and Windows, see docs/Rakefile's build task and scripts/crosscompile. You'll need a cross-compilation environment, such as Mingw for cross-compiling for Windows.

Cross-compilation requires a clean workspace, then:

# git clean ...
autoreconf -i
./configure
make distclean
scripts/crosscompile <name-of-build> <configure-options>

Use the --host= and --target= ./configure options to select a cross-compilation environment. See also "Cross compilation" on the wiki.

Send questions to https://stackoverflow.com/questions/tagged/jq or to the #jq channel (http://irc.lc/freenode/%23jq/) on Freenode (https://webchat.freenode.net/).

Comments
  • Generate array always for specified xml element

    Generate array always for specified xml element

    • Generate array always for specified xml element "aitem" even with single set .
    • It must open square braces as an array like aitem[{}]
    • Please also specify expression to write in /.jq file as a def, to maintain many single set items to be an array.
    <root>
        <aitem>
            <name>abc</name>
            <value>123</value>
        </aitem>
        <bitem>
            <name>bbbb</name>
            <value>2222</value>
        </bitem>
        <bitem>
            <name>BB</name>
            <value>22</value>
        </bitem>
    </root>
    
    

    Normal Output aitem{} bitem[{}{}]

     {
      "root": {
        "aitem": {
          "name": "abc",
          "value": "123"
        },
        "bitem": [
          {
            "name": "bbbb",
            "value": "2222"
          },
          {
            "name": "BB",
            "value": "22"
          }
        ]
      }
    }
    

    Expected Output , aitem[{}] bitem[{}{}] even its single set aitem must become array

    {
      "root": {
        "aitem": [
        {
          "name": "abc",
          "value": "123"
        }
        ],
        "bitem": [
          {
            "name": "bbbb",
            "value": "2222"
          },
          {
            "name": "BB",
            "value": "22"
          }
        ]
      }
     }
    
  • is it possible to insert key value from 2nd array into 1st

    is it possible to insert key value from 2nd array into 1st

    Not sure if this is possible.

      "questions": [
        {
          "season": 1,
          "episode": 1,
          "question": "what is the name of the character played by Michael Richards?"
        }
      ],
      "episodes": [
        {
          "season": 1,
          "episode": 1,
          "title": "The Seinfeld Chronicles"
        },
        {
          "season": 1,
          "episode": 2,
          "title": "The Stake Out"
        }
      ]
    

    looking to insert 2nd array title, if it matches the season and episode of 1st array

    so it would add "title": "The Seinfeld Chronicles" to the questions array for season1 and episode1.

  • Can't chain generic object indexes

    Can't chain generic object indexes

    Describe the bug When selecting subfields (e.g. .foo.bar), using the generic notation (e.g. .["foo"].["bar"]) throws a syntax error.

    To Reproduce Given the input (sample.json):

    {
      "title": "Title 1",
      "media:content": {
        "media:credits": "media:content.media:credits 1"
      }
    }
    

    I want to pull .media-content.media:credits to the top level and relabel the field to "credits" like this:

    $ cat sample.json | jq '{title, credits: .["media:content"].["media:credits"]}'
    
    

    Expected output

    {
      "title": "Title 1",
      "credits": "media:content.media:credits 1"
    }
    

    Actual output

    jq: error: syntax error, unexpected '[', expecting FORMAT or QQSTRING_START (Unix shell quoting issues?) at <top-level>, line 1:
    {title, credits: .["media:content"].["media:credits"]}
    jq: 1 compile error
    

    Environment (please complete the following information):

    • OS and Version: macOS Ventura 13.1
    • jq version: 1.6

    Additional context If the keys can be used in identifier-like syntax, like this, then it works: (sample2.json)

    {
      "title": "Title 1",
      "content": {
        "credits": "content.credits 1",
      },
    }
    
    $ cat sample2.json | jq '{title, credits: .content.credits}'
    
    {
      "title": "Title 1",
      "credits": "content.credits 1"
    }
    

    But even then , it still doesn't work with the generic quoted syntax chained after the first selector

    $ cat sample2.json | jq '{title, credits: .["content"].["credits"]}'  # Error
    $ cat sample2.json | jq '{title, credits: .content.["credits"]}'      # Error
    $ cat sample2.json | jq '{title, credits: .["content"].credits}'      # Works
    

    Addendum: While writing this, I did finally discover a workaround using the pipe operator:

    $ cat sample2.json | jq '{title, credits: .["content"] | .["credits"]}'.            # Works
    $ cat sample.json | jq '{title, credits: .["media:content"] | .["media:credits"]}'. # Works
    

    But I'm filing the bug report anyways because, according to the docs, .foo.bar should be equivalent to .["foo"].["bar"]. (and likewise, .["foo"].["bar"] should be equivalent to .["foo'] | .["bar"]

    Thanks for the tool!

  • Name of MacOS binary ends in

    Name of MacOS binary ends in "-amd64"

    On your download page https://stedolan.github.io/jq/download/, the name of the MacOS binary for v1.6 is "jq-osx-amd64". Apple has never used AMD CPUs, so what architecture is this binary actually for? If it really is for Macs, you should change it's misleading name.

  • Unrecognized options --nul-output, --binary on Windows

    Unrecognized options --nul-output, --binary on Windows

    jq issues "Unknow option" when trying to pass either --nul-output or --binary to the executable.

    ` C:>jq --version jq-1.6

    C:>jq --binary /cygdrive/c/Programs/cygwin64/bin/jq: Unknown option --binary Use /cygdrive/c/Programs/cygwin64/bin/jq --help for help with command-line options, or see the jq manpage, or online docs at https://stedolan.github.io/jq

    C:>jq --nul-output /cygdrive/c/Programs/cygwin64/bin/jq: Unknown option --nul-output Use /cygdrive/c/Programs/cygwin64/bin/jq --help for help with command-line options, or see the jq manpage, or online docs at https://stedolan.github.io/jq

    C:>jq-win --version jq-1.6

    C:>jq-win --binary C:\Software\utils\jq-win.exe: Unknown option --binary Use C:\Software\utils\jq-win.exe --help for help with command-line options, or see the jq manpage, or online docs at https://stedolan.github.io/jq

    C:>jq-win --nul-output C:\Software\utils\jq-win.exe: Unknown option --nul-output Use C:\Software\utils\jq-win.exe --help for help with command-line options, or see the jq manpage, or online docs at https://stedolan.github.io/jq `

  • `id` integer field showing the same value in result, when diffent in original json file.

    `id` integer field showing the same value in result, when diffent in original json file.

    Describe the bug For some json files there is strange behavior for id field. I see the same value in result view, but in input json file the id value are distinct. Here is the result what I see https://ibb.co/7GsQn2g . Original json is below. Result:

    $ cat test_failure.json | jq
    {
      "sections": [
        {
          "items": [
            {
              "id": 50000000014435120,
              "price": {
                "full": 3450
              }
            },
            {
              "id": 50000000014435120,
              "price": {
                "full": 3450
              }
            },
            {
              "id": 50000000014435120,
              "price": {
                "full": 3450
              }
            },
            {
              "id": 50000000014435120,
              "price": {
                "full": 3450
              }
            }
          ],
          "name": "cancelled"
        }
      ]
    }
    

    To Reproduce json: { "sections": [ { "items": [ { "id": 50000000014435121, "price": { "full": 3450 } }, { "id": 50000000014435122, "price": { "full": 3450 } }, { "id": 50000000014435123, "price": { "full": 3450 } }, { "id": 50000000014435124, "price": { "full": 3450 } } ], "name": "cancelled" } ] }

    command: cat test_failure.json | jq

    Expected behavior all id-s are different as in raw json.

    Environment (please complete the following information):

    • Ubuntu 18.04
    • jq-1.5-1-a5b5cbe

    Additional context I see this bug also in Firefox and Google Chrome. I think the use this library for preview of json.

Related tags
Json-match - Command line util for matching values in a JSON input

json-match Match JSON input by specifying key and value > json-match -json '{\"p

Jan 12, 2022
An open-source GitLab command line tool bringing GitLab's cool features to your command line
An open-source GitLab command line tool bringing GitLab's cool features to your command line

GLab is an open source GitLab CLI tool bringing GitLab to your terminal next to where you are already working with git and your code without switching

Dec 30, 2022
A command line tool that builds and (re)starts your web application everytime you save a Go or template fileA command line tool that builds and (re)starts your web application everytime you save a Go or template file

# Fresh Fresh is a command line tool that builds and (re)starts your web application everytime you save a Go or template file. If the web framework yo

Nov 22, 2021
A command line tool to prompt for a value to be included in another command line.

readval is a command line tool which is designed for one specific purpose—to prompt for a value to be included in another command line. readval prints

Dec 22, 2021
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.

dasel Dasel (short for data-selector) allows you to query and modify data structures using selector strings. Comparable to jq / yq, but supports JSON,

Jan 2, 2023
🔄 A command-line utility to export Protocol Buffers (proto) files to YAML, and JSON

proto2yaml ?? A command-line utility to export Protocol Buffers (proto) files to YAML, and JSON. Currently supported exports are for: Packages Service

Nov 10, 2022
A simple command line for convert CSV in JSON
A simple command line for convert CSV in JSON

C2J A simple command line for convert CSV in JSON list of objects based on header. Install With Go 1.17 or higher: go install github.com/edermanoel94/

Dec 14, 2022
rj is a command line tool show the HTTP Response as JSON
rj is a command line tool show the HTTP Response as JSON

rj rj is a command line tool show the HTTP Response as JSON Installation

Dec 31, 2022
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Jan 8, 2023
git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.
git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.

Table of contents Introduction Reference Contributing Introduction Overview git-xargs is a command-line tool (CLI) for making updates across multiple

Dec 31, 2022
git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command
git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command

git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command. You give git-xargs:

Feb 5, 2022
Package command provide simple API to create modern command-line interface

Package command Package command provide simple API to create modern command-line interface, mainly for lightweight usage, inspired by cobra Usage pack

Jan 16, 2022
A command line tool for simplified docker volume command built with go

dockervol A command line tool for simplified docker volume command built with go. Features: Remove anonymous volume (beta) Remove volume by matching n

Dec 18, 2021
Watcher - A simple command line app to watch files in a directory for changes and run a command when files change!

Watcher - Develop your programs easily Watcher watches all the files present in the directory it is run from of the directory that is specified while

Mar 27, 2022
Use the command to convert arbitrary formats to Go Struct (including json, toml, yaml, etc.)

go2struct-tool Use the command to convert arbitrary formats to Go Struct (including json, toml, yaml, etc.) Installation Run the following command und

Dec 16, 2021
LINE account link: Sample code for LINE account link
LINE account link: Sample code for LINE account link

LINE account link: Sample code for LINE account link This is sample code to demostration LINE chatbot account link, refer to document https://develope

Dec 11, 2021
argv - Go library to split command line string as arguments array using the bash syntax.

Argv Argv is a library for Go to split command line string into arguments array. Documentation Documentation can be found at Godoc Example func TestAr

Nov 19, 2022
CLI - A package for building command line app with go
CLI - A package for building command line app with go

Command line interface Screenshot Key features Lightweight and easy to use. Defines flag by tag, e.g. flag name(short or/and long), description, defau

Dec 23, 2022
Simple and complete API for building command line applications in Go

Simple and complete API for building command line applications in Go Module cli provides a simple, fast and complete API for building command line app

Nov 23, 2022