What is a jq tester?
jq is a command-line tool for slicing, filtering and reshaping JSON. You write a short program called a filter, jq feeds your JSON through it, and the result comes out as new JSON. Developers use it daily to read API responses, to pull fields out of logs and to build the JSON that another command needs.
The catch is that a filter is easier to get right when you can see the output change as you type. This page does that. It runs the real jq 1.8, the same C program you install from a package manager, compiled to WebAssembly. It is not a re-implementation, so what you see here is what jq prints in a terminal. Everything runs inside your browser, in a background worker, and your JSON never leaves your device.
The options that matter in daily use are switches on the page: compact output (-c), raw strings (-r), sorted keys (-S), slurp (-s) and no input (-n). Other command-line flags, such as --arg, are not offered, and neither is reading files from disk. The filter sees only the JSON you pasted.
A filter that never ends would freeze a normal page, so jq runs in a worker and is stopped after 8 seconds with a message. A result that needs more memory than WebAssembly can give, such as an endless list, is reported as an error too.
How to test a jq filter
- Paste your JSON into the JSON field. The "Example" button loads a small bookstore document.
- Type the filter in the jq filter field. The output refreshes a moment after you stop typing.
- Turn on the switches you need. Compact prints each result on one line, raw strings removes the quotes from strings, sort keys orders object keys, slurp reads all the input values into one array and no input starts the filter with
nullinstead of your JSON. - Read the output. The counter shows how many lines jq printed.
- Copy the result or download it as a file.
- If jq complains, the message is jq's own, for example about a syntax error. Fix the filter and the error goes away.
Examples
These use the bookstore document from the Example button. The outputs were checked against the jq command line.
Select books under 10
Filter:
.store.book[] | select(.price < 10) | .titleOutput (one JSON string per line):
"Sayings of the Century"
"Moby Dick"Raw strings and compact output
With "raw strings" on, .store.book[].author prints the names without quotes:
Nigel Rees
Evelyn Waugh
Herman Melville
J. R. R. TolkienWith "compact" on, .store.book | map({t: .title, p: .price}) | sort_by(.p) | .[0] prints the cheapest book on one line:
{"t":"Sayings of the Century","p":8.95}Group, add and generate
[.store.book[].price] | add returns 53.92. .store.book | group_by(.category) | map({(.[0].category): length}) | add with compact output returns:
{"fiction":3,"reference":1}With "no input" on, the filter [limit(3; range(10))] ignores your JSON and prints [0,1,2] in compact mode. With "slurp" on and the text 1 2 3 as input, the filter add prints 6.
Common mistakes
- A filter that does not compile.
.[gives a syntax error, and.a | frobnicatesaysfrobnicate/0 is not defined. The words are jq's. - A runtime error. Indexing something that is not an object, or calling
error("boom"), stops jq with a message. Check the shape of your data withtypeorkeys. - Expecting an error for a missing key.
.nope.deeperis valid and returnsnull. - Empty output. A filter such as
empty, or aselectthat matches nothing, prints nothing. The page says the filter ran and printed no output. - Input that is not JSON. A stray comma or a single quote breaks the document. jq reports the problem before running the filter.
- Quotes around the filter. In a shell you wrap the filter in single quotes. Here, type it as it is.
- A loop without an end. Something like
repeatwith no stop condition is cut after 8 seconds. Uselimit(n; ...)to bound it.
Frequently asked questions
Is this the real jq?
Yes. It is jq 1.8 compiled to WebAssembly, so the results match the command-line tool for the same filter and input.
Why was my filter stopped after 8 seconds?
The filter ran for longer than 8 seconds, usually because of an infinite loop or a huge range. The worker is stopped so the page stays responsive. Bound the work with limit or a smaller range.
Can I use --arg, files or environment variables?
No. Only the five switches on the page are available, and the filter works on the pasted JSON. For selecting by path only, the JSONPath tester is lighter.
How do I clean up the output afterwards?
Copy it to JSON Prettify to format or minify it, or compare two results with JSON Diff.