<p>Ok tried to understand your problem exactly... This is what is happening:</p>

<pre><code>$ echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq | grep value
jq - commandline JSON processor [version 1.5-1-a5b5cbe]
Usage: jq [options] &lt;jq filter&gt; [file...]
[rest of output is omitted for brevity]
</code></pre>

<p>The important thing to notice here is the usage line (emphasis is mine):</p>

<blockquote>
  <p>Usage: jq [options] <strong>&lt;jq filter&gt;</strong> [file...]</p>
</blockquote>

<p>The filter is not optional, if you don't give one, jq tries to parse the rest of the command line as its filter and throws an error. A workaround for your case here is:</p>

<pre><code>$ echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq '.' | grep value
  "value": "New",
</code></pre>

<p>which indeed greps the "value" line as the filter passed is '.' - this just pretty prints the json content, but that's far from the best use of jq. If you wish to get only this line it would be better do:</p>

<pre><code>$ echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq '.value'
"New"
</code></pre>

<p>If you wish to get the output without quotes then you can add add <code>-r</code> option to jq like so:</p>

<pre><code>$ echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq -r '.value'
New
</code></pre>

<p>from <code>jq --help</code>:</p>

<blockquote>
  <p>-r     output raw strings, not JSON texts;</p>
</blockquote>

<p>that's a little introduction to jq, that's probably not enough to solve your problem at all but as you didn't specify your problem I can't help more than that.</p>

CC BY-SA 3.0
2017-12-20T16:40:26.147Z
I think you may have been overthinking my problem. This was exactly the solution. An empty filter resolves the issue.
James Shewey
CC BY-SA 4.0
2017-12-20T09:28:30.143Z
2020-05-22T17:32:15.087Z
2020-05-22T17:32:15.087Z
Tensibai
<p>I recently learned about an outstanding little tool, <a href="https://community.theforeman.org/t/friday-tip-of-the-day-use-jq-to-parse-json/7691" rel="noreferrer">jq</a> that allows you to pipe unformatted JSON output into it and then have that output reformatted and output to the screen in a very nicely formatted color-coded json layout. Eg:</p>

<pre><code>echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq
</code></pre>

<p>I have found however, that I am unable to pipe the formatted results (from jq) into additional tools in my standard toolset, such as grep, sed, awk, etc. How can I make make this output pipe-able? Eg, this doesn't work:</p>

<pre><code>'{"value": "New", "onclick": "CreateNewDoc()"}' | jq | grep value
</code></pre>

CC BY-SA 3.0
2017-12-20T16:57:09.210Z
This seems to be a usage question on a general-purpose command-line tool. It seems more appropriate for Super User or Linux & Unix?
Xiong Chiamiov
CC BY-SA 3.0
2017-12-20T18:11:57.750Z
@XiongChiamiov - I posted here because DevOps seems significantly more likely to interact with JSON/REST and would benefit from 1) knowing about such a tool and 2) it's proper usage. I would categorize this as a *DevOps* command line tool, not general purpose.
James Shewey
CC BY-SA 3.0
2017-12-26T18:43:32.357Z
My devs are far more familiar with these sorts of tools than I am, because they're *building APIs* and thus testing them constantly throughout the day.  While that will of course vary from company to company, I still think that curl/httpie/jq/etc. are just general-purpose programmer-y tools, not DevOps-related tools at all.
Xiong Chiamiov
<json>
How can I pipe jq output
James Shewey
# How can I pipe jq output

(Asked by: username_0 on 2017-12-19)

I recently learned about an outstanding little tool, jq that allows you to pipe unformatted JSON output into it and then have that output reformatted and output to the screen in a very nicely formatted color-coded json layout. Eg:
echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq

I have found however, that I am unable to pipe the formatted results (from jq) into additional tools in my standard toolset, such as grep, sed, awk, etc. How can I make make this output pipe-able? Eg, this doesn't work:
'{"value": "New", "onclick": "CreateNewDoc()"}' | jq | grep value

**Tags:** json

> **Comments:**
> **username_1**: This seems to be a usage question on a general-purpose command-line tool. It seems more appropriate for Super User or Linux & Unix?  
> **username_0**: @XiongChiamiov - I posted here because DevOps seems significantly more likely to interact with JSON/REST and would benefit from 1) knowing about such a tool and 2) it's proper usage. I would categorize this as a *DevOps* command line tool, not general purpose.  
> **username_1**: My devs are far more familiar with these sorts of tools than I am, because they're *building APIs* and thus testing them constantly throughout the day.  While that will of course vary from company to company, I still think that curl/httpie/jq/etc. are just general-purpose programmer-y tools, not DevOps-related tools at all.  

---

## 1 answers

### Answer by username_2 on 2017-12-20. Score: 16 | Accepted answer

Ok tried to understand your problem exactly... This is what is happening:
$ echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq | grep value
jq - commandline JSON processor [version 1.5-1-a5b5cbe]
Usage: jq [options]  [file...]
[rest of output is omitted for brevity]

The important thing to notice here is the usage line (emphasis is mine):

Usage: jq [options]  [file...]

The filter is not optional, if you don't give one, jq tries to parse the rest of the command line as its filter and throws an error. A workaround for your case here is:
$ echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq '.' | grep value
  "value": "New",

which indeed greps the "value" line as the filter passed is '.' - this just pretty prints the json content, but that's far from the best use of jq. If you wish to get only this line it would be better do:
$ echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq '.value'
"New"

If you wish to get the output without quotes then you can add add -r option to jq like so:
$ echo '{"value": "New", "onclick": "CreateNewDoc()"}' | jq -r '.value'
New

from jq --help:

-r     output raw strings, not JSON texts;

that's a little introduction to jq, that's probably not enough to solve your problem at all but as you didn't specify your problem I can't help more than that.

> **Comments:**
> **username_0**: I think you may have been overthinking my problem. This was exactly the solution. An empty filter resolves the issue.  

---

