Pikkola jq, tool No. 67

Ask the JSON a question.

Paste an API response, an export or a config file. Write a jq filter or a JSONPath path, and the rows appear as you type: what matched, what type each value is, and a CSV to take away. The document stays in the tab.

4
real documents
2
query languages
0
uploads

checked against jq 1.7 on 157 queries

The playground

One document, one question, the rows

The document sits on the left. The query sits above the answer. Everything is evaluated in this tab as you type, with a pause of a quarter second so a long query does not run on every keystroke.

Real documents
JSON document JSON
Result

              

No result yet. Pick a document and a query, or press one of the samples above.

Nothing leaves the tab

No request, no account, no storage of the document. The Content-Security-Policy sets connect-src to none, so the page could not upload a record even if it tried.

Under the query

A parser, a tree and a stream

The query is read by a tokenizer and a recursive descent parser, then walked over the parsed JSON. No part of it is handed to eval or to the Function constructor, because this page runs under a policy that would refuse them anyway.

01

jq is a stream, not a table

A filter takes one value and can return zero, one or many. A pipe feeds each output to the next filter, and a comma joins two streams. The result pane shows the whole stream, and the line above it counts the values.

02

Every error has a column

The tokenizer knows where each token starts and each node keeps that position. A missing bracket, an unknown function or an index on a string is reported with the line and the column of the query, not with a stack trace.

03

The subset is stated

The cheat sheet lists every function this page implements. Anything else stops with a message that names it, rather than returning a quiet null. Where a query is supported, its output is compared with jq 1.7 in the build.

What is in, and what stops

Enough of jq for the work people actually bring to a JSON file, and a clear edge where the rest begins. JSONPath has its own, shorter list.

  • jq
    Paths, streams and constructors.field, .["key"], .[], [0], [-1], [1:3], .., the optional ? and the default //. Arrays [ ], objects { } with shorthand, and strings with \(interpolation).
  • jq
    The operators and the control flow+ - * / %, == != < <= > >=, and, or, not, if then elif else end, as $x, reduce, try catch, and the update forms = |= += -= *= /= %= //=.
  • jq
    The list and object functionsselect, map, map_values, length, keys, has, in, add, min, max, min_by, max_by, sort, sort_by, group_by, unique, unique_by, reverse, flatten, first, last, nth, range, any, all, contains, inside, to_entries, from_entries, with_entries, paths, path, del, getpath, setpath.
  • jq
    The text functionssplit, join, startswith, endswith, ltrimstr, rtrimstr, ascii_upcase, ascii_downcase, tonumber, tostring, tojson, fromjson, index, rindex, indices, and the formats @csv, @tsv, @json, @text, @sh, @uri, @html, @base64, @base64d.
  • stop
    Definitions, streaming and the outside worlddef, foreach, label and break, input and inputs, $ENV, the regex functions test, match, capture, sub and gsub, and SQL style operators. A query that uses one of them stops with its name and position. For those, run jq itself.
  • JSONPath
    Paths with filters$ root, .child, ['key'], [0], [-1], [0,1], [1:3], [*], .*, recursive .., and filters with == != < <= > >=, &&, ||, !, existence tests, =~ /regex/ and @.a.b references. length(), count(), min(), max(), sum() and avg() end a path.

Reference

The cheat sheet, on the page

The same groups you get from the button in the studio, written out so a search engine can find them too. Each line is a query that works on the samples above.

Pikkola Watch

The same attention, every morning, without you asking.

The tool in front of you reads a document once, when you paste it. Watch reads up to ten domains every day and sends one message when a certificate slips, a page stops answering or a security header disappears. It is the same idea, pointed at a live site.

  • Daily check of every domain, from the edge.
  • A broken redirect, an expiring certificate, a missing header.
  • One message in Slack, Discord or your own webhook.

$7a month

$70 a year, two months free

See what Watch checks

Ten domains, one check a day, $0 to start on this page.

Made by one person, free to use

Questions

Is this the real jq?

No. It is a jq style interpreter written in JavaScript for this page, and its output is compared with jq 1.7 on 157 queries in the build. The common filters, constructors, arithmetic, if, as, reduce and the list and string functions are here. def, foreach, label and input are not, and a query that uses them stops with its name instead of guessing.

Is my document sent anywhere?

No. The parser, the evaluator and the sample documents are files on this domain. The Content-Security-Policy sets connect-src to none, so there is no endpoint the page could reach, and a document is never written to storage.

Why is the result an array when my query returns one row?

jq calls its output a stream: a query can emit zero, one or many values. The page shows the whole stream. One value is shown as itself, several are shown as an array, and the line under the result says which one you are looking at. A filter that ends in .[] usually turns one array into many rows.

How do I get a table for a spreadsheet?

Use the CSV or TSV tab and press Copy or Download. When every row is an object, the columns are the union of the keys, in the order they first appear. A single array of objects becomes its rows. Values that are not scalars are written as JSON, and a value that holds a comma or a quote is quoted the way CSV expects.

Can it open a file?

Yes, with Open a file. The browser reads it, the page parses it, and it stays in the tab. It is not uploaded and it is not kept between visits. A JSON Lines file is not valid JSON; wrap the lines in an array first, or pick the sample that matches the shape.

What is the limit?

A document of a few megabytes is comfortable. A query is stopped by a step budget before it can freeze the page, and a stream is capped at fifty thousand values, so a bare dot on a million records asks for a narrower query. When that happens the message says which limit was reached.

Which should I use, jq or JSONPath?

JSONPath is shorter when you only need to point at values: $..book[?(@.price < 10)].title. jq is a language: it can also rebuild objects, group, add and format. If the answer is a set of values, either works. If the answer is a new document, use jq.