ChatGPT解决这个技术问题 Extra ChatGPT

How to remove double-quotes in jq output for parsing json files in bash?

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?

FYI, 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).
Another example of a case where the difference is a big one is 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.

3
3 revs, 2 users 83%

Use the -r (or --raw-output) option to emit raw strings as output:

jq -r '.name' <json.txt

What if I don't want to unescape anything and just want to strip the quotes?
It sounds like you have detailed enough specifications that you should be asking a new question, so that specification can be given in full. This back-and-forth method of figuring out what you want (what your input is, what your expected output is, where the boundary between your jq and bash code lives, etc) is not helpful.
If you want to strip the quotes while remaining in jq, that distinguishes your question from the OP's, who wanted a string without quotes in bash. Once again, I'm done here until/unless you link to a new question.
If you want to strip the quotes, just pipe the output from this command to tr -d '"'.
Whether any given corner case is safe to ignore needs to be an explicit, case-by-case design consideration as a rule. Otherwise you end up in the world we live in, where software is riddled with bugs because the design didn't consider the full scope of possible inputs. Which is to say -- unless someone lays out as a requirement that " 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)