I'm using jq to parse a JSON file as shown here. However, the results for string values contain the "double-quotes" as expected, as shown below:
$ cat json.txt | jq '.name'
"Google"
How can I pipe this into another command to remove the ""? so I get
$ cat json.txt | jq '.name' | some_other_command
Google
What some_other_command
can I use?
cat foo | bar
is significantly less efficient than bar <foo
or its equivalent <foo bar
, especially if bar
is a program like sort
that can parallelize its operations when given a seekable file descriptor as opposed to a FIFO (which can only be read once front-to-back). It both means more startup overhead (invoking /bin/cat
), and more context switches between userspace and kernel (each piece of content going through a read()
within cat
, then a write()
to a FIFO in cat
, and then a read()
inside your destination program, instead of skipping to that last step directly).
cat foo | wc -c
, vs wc -c <foo
-- in the latter case it can just do two syscalls, seek()
and tell()
, to get the exact size of the file now matter how long it is; in the former, it needs to read to the end, even if that's gigabytes of content, because only cat
has direct access to the original file, and wc
has no way to request metadata on it.
Use the -r
(or --raw-output
) option to emit raw strings as output:
jq -r '.name' <json.txt
Success story sharing
tr -d '"'
."
can never exist as literal data as opposed to syntax, it's irresponsible to assume such to be the case. (I work in security, and see sooo many issues misclassified as "input validation" failures when they're really failure to design for the full input domain)