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

Related tags

JSON jq
Overview

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  

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"
          }
        ]
      }
     }
    
    opened by ajit4sbi 5
  • 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.

    opened by chrismccoy 1
  • 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!

    opened by partap 4
  • 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.

    opened by Twangist 2
  • 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 `

    opened by apsen-github 0
  • `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.

    opened by melonaerial 5
Releases(jq-1.6)
  • jq-1.6(Nov 2, 2018)

    New in this release since 1.5:

    • Destructuring Alternation
    • New Builtins:
      • builtins/0
      • stderr/0
      • halt/0, halt_error/1
      • isempty/1
      • walk/1
      • utf8bytelength/1
      • localtime/0, strflocaltime/1
      • SQL-style builtins
      • and more!
    • Add support for ASAN and UBSAN
    • Make it easier to use jq with shebangs (8f6f28c)
    • Add $ENV builtin variable to access environment
    • Add JQ_COLORS env var for configuring the output colors

    Bug fixes:

    • Calling jq without a program argument now always assumes . for the program, regardless of stdin/stdout. (5fe0536)
    • Make sorting stable regardless of qsort. (7835a72)
    • Adds a local oniguruma submodule and the ./configure --with-oniguruma=builtin option to make it easier to build with oniguruma support on systems where you can't install system-level libraries. (c6374b6 and 02bad4b)
    • And much more!
    Source code(tar.gz)
    Source code(zip)
    jq-1.6.tar.gz(1.66 MB)
    jq-1.6.zip(1.84 MB)
    jq-linux32(2.65 MB)
    jq-linux64(3.77 MB)
    jq-osx-amd64(843.78 KB)
    jq-win32.exe(2.58 MB)
    jq-win64.exe(3.36 MB)
  • jq-1.5(Aug 16, 2015)

    Thanks to the 20+ developers who have sent us PRs since 1.4, and the many contributors to issues and the wiki.

    The manual for jq 1.5 can be found at https://stedolan.github.io/jq/manual/v1.5/

    Salient new features since 1.4:

    • regexp support (using Oniguruma)!

    • a proper module system

      import "foo/bar" as bar; # import foo/bar.jq's defs into a bar::* namespace

      and

      include "foo/bar"; # import foo/bar.jq's defs into the top-level

    • destructuring syntax (. as [$first, $second, {$foo, $bar}] | ...)

    • math functions

    • an online streaming parser

    • minimal I/O builtions (inputs, debug)

      One can now write:

      jq -n 'reduce inputs as $i ( ... )'

      to reduce inputs in an online way without having to slurp them first! This works with streaming too.

    • try/catch, for catching and handling errors (this makes for a dynamic non-local exit system)

    • a lexical non-local exit system

      One can now say

      label $foo | ..... | break $foo

      where the break causes control to return to the label $foo, which then produces empty (backtracks). There's named and anonymous labels.

    • tail call optimization (TCO), which allows efficient recursion in jq

    • a variety of new control structure builtins (e.g., while(cond; exp), repeat(exp), until(cond; next)), many of which internally use TCO

    • an enhanced form of reduce: foreach exp as $name (init_exp; update_exp; extract_exp)

    • the ability to read module data files

      import "foo/bar" as $bar; # read foo/bar.json, bind to $bar::bar

    • --argjson var '<JSON text>'

      Using --arg var bit me too many times :)

    • --slurpfile var "filename"

      Replaces the --argfile form (which is now deprecated but remains for backward compatibility).

    • support for application/json-seq (RFC7464)

    • a large variety of new utility functions, many being community contributions (e.g., bsearch, for binary searching arrays)

    • datetime functions

    • a variety of performance enhancements

    • def($a): ...; is now allowed as an equivalent of def(a): a as $a | ...;

    • test and build improvements, including gcov support

    Lastly, don't forget the wiki! The wiki has a lot of new content since 1.4, much of it contributed by the community.

    Source code(tar.gz)
    Source code(zip)
    jq-1.5.tar.gz(721.98 KB)
    jq-1.5.zip(729.88 KB)
    jq-linux32(1.52 MB)
    jq-linux32-no-oniguruma(1.24 MB)
    jq-linux64(2.88 MB)
    jq-osx-amd64(634.76 KB)
    jq-win32.exe(1.16 MB)
    jq-win64.exe(2.21 MB)
  • jq-1.5rc2(Jul 27, 2015)

    Thanks to the 20+ developers who have sent us PRs since 1.4, and the many contributors to issues and the wiki. We're nearing a 1.5 release, finally.

    Salient new features since 1.4:

    • regexp support (using Oniguruma)!

    • a proper module system

      import "foo/bar" as bar; # import foo/bar.jq's defs into a bar::* namespace

      and

      include "foo/bar"; # import foo/bar.jq's defs into the top-level

    • destructuring syntax (. as [$first, $second, {$foo, $bar}] | ...)

    • math functions

    • an online streaming parser

    • minimal I/O builtions (inputs, debug)

      One can now write:

      jq -n 'reduce inputs as $i ( ... )'

      to reduce inputs in an online way without having to slurp them first! This works with streaming too.

    • try/catch, for catching and handling errors (this makes for a dynamic non-local exit system)

    • a lexical non-local exit system

      One can now say

      label $foo | ..... | break $foo

      where the break causes control to return to the label $foo, which then produces empty (backtracks). There's named and anonymous labels.

    • tail call optimization (TCO), which allows efficient recursion in jq

    • a variety of new control structure builtins (e.g., while(cond; exp), repeat(exp), until(cond; next)), many of which internally use TCO

    • an enhanced form of reduce: foreach exp as $name (init_exp; update_exp; extract_exp)

    • the ability to read module data files

      import "foo/bar" as $bar; # read foo/bar.json, bind to $bar::bar

    • --argjson var '<JSON text>'

      Using --arg var bit me too many times :)

    • --slurpfile var "filename"

      Replaces the --argfile form (which is now deprecated but remains for backward compatibility).

    • support for application/json-seq (RFC7464)

    • a large variety of new utility functions, many being community contributions (e.g., bsearch, for binary searching arrays)

    • datetime functions

    • a variety of performance enhancements

    • def($a): ...; is now allowed as an equivalent of def(a): a as $a | ...;

    • test and build improvements, including gcov support

    Lastly, don't forget the wiki! The wiki has a lot of new content since 1.4, much of it contributed by the community.

    Source code(tar.gz)
    Source code(zip)
    jq-1.5rc2.tar.gz(697.31 KB)
    jq-1.5rc2.zip(739.09 KB)
    jq-linux-x86(1.39 MB)
    jq-linux-x86_64(3.04 MB)
    jq-osx-x86_64(634.89 KB)
    jq-win32.exe(1.16 MB)
    jq-win64.exe(2.21 MB)
  • jq-1.5rc1(Jan 1, 2015)

    Salient new features since 1.4:

    • regexp support (using Oniguruma)

    • an online streaming parser

      Included is the ability to control reading of inputs from the jq program, using the new input and inputs builtins.

      Finally we can write:

      jq -n 'reduce inputs as $i ( ... )' # reduce online!

      to reduce inputs without slurping them first. This works with streaming too.

    • try/catch, for catching and handling errors (this makes for a dynamic non-local exit system)

    • a lexical non-local exit system

      Using try/catch to break out of control structures was not a good thing. A lexical mechanism is.

      You can now say

      label $foo | ..... | break $foo

      where the break causes control to return to the label $foo, which then produces empty (backtracks). There's named and anonymous labels.

    • tail call optimization (TCO), which allows efficient recursion in jq

    • a variety of new control structure builtins (e.g., while(cond; exp), repeat(exp), until(cond; next))

    • an enhanced form of reduce: foreach exp as $name (init_exp; update_exp; extract_exp)

    • a proper module system

      import "foo/bar" as bar; # import foo/bar.jq's defs into a bar::* namespace

    • the ability to read module data files

      import "foo/bar" as $bar; # read foo/bar.json, bind to $bar::bar

    • --argjson var '<JSON text>'

      Using --arg var bit me too many times :)

    • --in-place / -i for in-place editing of files

    • support for application/json-seq.

    • a variety of new utility functions, many being community contributions

    • a variety of performance enhancements (e.g., constant folding)

    • def($a): ...; is now allowed as an equivalent of def(a): a as $a | ...;

    Lastly, don't forget the wiki! It has a lot of new content since 1.4, much of it contributed by the community.

    Source code(tar.gz)
    Source code(zip)
    jq-1.5rc1.tar.gz(630.66 KB)
    jq-linux-x86_64-static(3.26 MB)
    jq-win32.exe(1.46 MB)
    jq-win64.exe(1.29 MB)
    jq.1(77.38 KB)
  • jq-1.2(Aug 8, 2015)

  • jq-1.1(Aug 8, 2015)

  • jq-1.0(Aug 8, 2015)

https://github.com/json-c/json-c is the official code repository for json-c. See the wiki for release tarballs for download. API docs at http://json-c.github.io/json-c/

\mainpage json-c Overview and Build Status Building on Unix Prerequisites Build commands CMake options Testing Building with vcpkg Linking to libjson-

json-c 2.6k Dec 31, 2022
A curated list of awesome things built with the JSON processor and turing-complete functional language jq.

A curated list of awesome things built with the JSON processor and turing-complete functional language jq.

fiatjaf 578 Jan 3, 2023
advanced, flexible JSON manipulation in C

WJElement - JSON manipulation in C WJElement is a very flexible JSON library developed by Messaging Architects. It was created for MA's "WARP" webserv

netmail 102 Dec 28, 2022
This is a JSON C++ library. It can write and read JSON files with ease and speed.

Json Box JSON (JavaScript Object Notation) is a lightweight data-interchange format. Json Box is a C++ library used to read and write JSON with ease a

Anhero inc. 110 Dec 4, 2022
json-cpp is a C++11 JSON serialization library.

JSON parser and generator for C++ Version 0.1 alpha json-cpp is a C++11 JSON serialization library. Example #include <json-cpp.hpp> struct Foo {

Anatoly Scheglov 7 Oct 30, 2022
A convenience C++ wrapper library for JSON-Glib providing friendly syntactic sugar for parsing JSON

This library is a wrapper for the json-glib library that aims to provide the user with a trivial alternative API to the API provided by the base json-

Rob J Meijer 17 Oct 19, 2022
json-build is a zero-allocation JSON serializer compatible with C89

json-build is a zero-allocation JSON serializer compatible with C89. It is inspired by jsmn, a minimalistic JSON tokenizer.

Lucas Müller 31 Nov 16, 2022
Lightweight JSON library written in C.

About Parson is a lightweight json library written in C. Features Full JSON support Lightweight (only 2 files) Simple API Addressing json values with

Krzysztof Gabis 1.2k Dec 31, 2022
Lightweight, extremely high-performance JSON parser for C++11

sajson sajson is an extremely high-performance, in-place, DOM-style JSON parser written in C++. Originally, sajson meant Single Allocation JSON, but i

Chad Austin 546 Dec 16, 2022
🔋 In-place lightweight JSON parser

?? JSON parser for C This is very simple and very powerful JSON parser. It creates DOM-like data structure and allows to iterate and process JSON obje

Recep Aslantas 23 Dec 10, 2022
📟 JSON library for Arduino and embedded C++. Simple and efficient.

ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things). Features JSON deserialization Optionally decodes UTF-16 escape sequences t

Benoît Blanchon 6k Jan 3, 2023
JSON parser and generator for C/C++ with scanf/printf like interface. Targeting embedded systems.

JSON parser and emitter for C/C++ Features ISO C and ISO C++ compliant portable code Very small footprint No dependencies json_scanf() scans a string

Cesanta Software 637 Dec 30, 2022
C library for encoding, decoding and manipulating JSON data

Jansson README Jansson is a C library for encoding, decoding and manipulating JSON data. Its main features and design principles are: Simple and intui

Petri Lehtinen 2.7k Dec 31, 2022
🗄️ single header json parser for C and C++

??️ json.h A simple single header solution to parsing JSON in C and C++. JSON is parsed into a read-only, single allocation buffer. The current suppor

Neil Henning 544 Jan 7, 2023
a JSON parser and printer library in C. easy to integrate with any model.

libjson - simple and efficient json parser and printer in C Introduction libjson is a simple library without any dependancies to parse and pretty prin

Vincent Hanquez 260 Nov 21, 2022
A simple class for parsing JSON data into a QVariant hierarchy and vice versa.

The qt-json project is a simple collection of functions for parsing and serializing JSON data to and from QVariant hierarchies. NOTE: Qt5 introduced a

null 305 Dec 13, 2022
RapidJSON is a JSON parser and generator for C++.

A fast JSON parser/generator for C++ with both SAX/DOM style API

Tencent 12.6k Dec 30, 2022
single-header json parser for c99 and c++

ghh_json.h a single-header ISO-C99 (and C++ compatible) json loader. why? obviously this isn't the first json library written for C, so why would I wr

garrison hinson-hasty 14 Dec 1, 2022
An easy-to-use and competitively fast JSON parsing library for C++17, forked from Bitcoin Cash Node's own UniValue library.

UniValue JSON Library for C++17 (and above) An easy-to-use and competitively fast JSON parsing library for C++17, forked from Bitcoin Cash Node's own

Calin Culianu 24 Sep 21, 2022