ArticleslgStudy

mathematics

Jq (programming language)

Jq (programming language) is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Jq (programming language) rather than just read about it. In short: jq is a widely-used command-line utility and very high-level, functional, domain-specific programming language designed for processing JSON data. jq filters its input data to produce modified output in a manner similar to AWK or sed. The input typically consists of one or more JSON values but may instead by one or more lines of text.

Jq (programming language) — main illustration
Jq (programming language) — illustration

Key takeaways

  • Jq (programming language) belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Jq (programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Jq (programming language) from memory before moving on to harder problems.

Reference excerpt

jq is a widely-used command-line utility and very high-level, functional, domain-specific programming language designed for processing JSON data. jq filters its input data to produce modified output in a manner similar to AWK or sed. The input typically consists of one or more JSON values but may instead by one or more lines of text. In jq, programs consist of filters that can be composed in pipelines that perform a variety of operations on their inputs.

History jq was created by Stephen Dolan, and released in October 2012. It was described as being "like sed for JSON data". Support for regular expressions was added in jq version 1.5. The original implementation of jq was in Haskell before being ported to the language C. The jq language was subsequently implemented in other programming languages:

gojq is an implementation in Go; jaq is an implementation with some variations in Rust; jqjq implements a substantial subset of jq in jq itself.

Use

Command-line use jq is typically used at the command line and can be used with other command-line utilities, such as GNU Wget. Here is an example showing how the output of a wget command can be piped to a jq filter to determine the category names associated with this Wikipedia page:

The output produced by this pipeline consists of a stream of JSON strings, the first few of which are:

The wget command above uses the MediaWiki API for this page to produce a JSON response. The pipe | allows the output of wget to be accessed by jq, a standard Unix shell mechanism. The jq filter shown is an abbreviation for the jq pipeline:

This corresponds to the nested JSON structure produced by the call to wget. Notice that the jq pipeline is constructed in the same manner using the | character as the Unix-style pipeline.

Embedded use jq provides a C API, libjq, allowing it to be used from C.

Modes of operation jq by default acts as a "stream editor" for JSON inputs, much like the sed utility is the "stream editor" for lines of text. However jq has several other modes of operation:

it can treat its input from one or more sources as lines of text; it can gather a stream of inputs from a specified source into a JSON array; it can parse its JSON inputs using a so-called "streaming parser" that produces a stream of [path, value] arrays for all "leaf" paths. The streaming parser is very useful when one of more of the JSON inputs is too large to fit in memory, since its memory needs are usually quite small. For example, for an arbitrarily large array of JSON objects, the peak memory need is little more than needed to handle the largest top-level object. These modes of operation can, within certain limitations, be combined.

Syntax and semantics

Types Every JSON value is also a value in jq, which accordingly has the data types shown in the table below.

null is a value, just like any other JSON scalar; it is not a pointer or a "null pointer". nan (corresponding to NaN) and infinite (see IEEE 754) are the only two jq scalars that are not also JSON values.

Forms Special syntactic forms exist for function creation, conditionals, stream reduction, and the module system.

Filters Here is an example of defining a named, parameterized filter for formatting an integer in any base from 2 to 36 inclusive. The implementation illustrates tacit (or point-free) programming:

The next example demonstrates the use of generators in the classic "SEND MORE MONEY" verbal arithmetic game:

Related software jq has inspired several clones and similar programs. gojq reimplements much of jq in Go. It also supports processing YAML files. jaq is a Rust implementation of jq developed using denotational semantics to formalize its behavior in cases where the original jq documentation is unclear or does not match its behavior. Mike Farah's yq is a jq-like program that supports several file formats, including JSON, YAML, and XML. Its syntax is not fully compatible with jq. Andrey Kislyuk's yq provides a collection of wrapper scripts that use jq to process YAML, XML, or TOML files.

Notes

References

Bibliography

Others

External links Official website FAQ on GitHub – jq FAQ The jq Programming Language page on the Rosetta Code comparative programming tasks project site

Illustrations

Jq (programming language) illustration

Worked examples

Example 1 — a first encounter with Jq (programming language)

Start with the simplest possible case. Write down what Jq (programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Jq (programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Jq (programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Jq (programming language)

In research
Jq (programming language) appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Jq (programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Jq (programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics 2012 software, Dynamically typed programming languages, Functional languages, so understanding it makes those chapters shorter.
In everyday life
Look for Jq (programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Jq (programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Jq (programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Jq (programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Jq (programming language) in simple terms?

jq is a widely-used command-line utility and very high-level, functional, domain-specific programming language designed for processing JSON data. jq filters its input data to produce modified output in a manner similar to AWK or sed. The input typically consists of one or more JSON values but may i…

Why does Jq (programming language) matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Jq (programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Jq (programming language).

Tags

  • 2012 software
  • Dynamically typed programming languages
  • Functional languages
  • Programming languages
  • Programming languages created in 2012
  • Query languages

Keep exploring