We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Here are a couple lines of a JSON in a file:
{"user":"alex","num":"509","time":"Tue Jun 4 22:26:08 PDT 2019","pwd":"/Users/alex/codes/ores/prompt-command","pid":8074,"exit_code":127,"cmd":"xxxx"} {"user":"alex","num":"510","time":"Tue Jun 4 22:26:47 PDT 2019","pwd":"/Users/alex/codes/ores/prompt-command","pid":8114,"exit_code":0,"cmd":"sed '0,1d' "$HOME/my_bash_history""} {"user":"alex","num":"511","time":"Tue Jun 4 22:26:55 PDT 2019","pwd":"/Users/alex/codes/ores/prompt-command","pid":8132,"exit_code":0,"cmd":"sed '0,1d' "$HOME/my_bash_history" | wc -l"}
not quote valid JSON because if you look at the bottom 2 lines, we have this pair:
"cmd":"sed '0,1d' "$HOME/my_bash_history" | wc -l"
so what we need is:
"cmd":"sed '0,1d' \"$HOME/my_bash_history\" | wc -l"
my question/request: does/can JQ provide a facility to escape/sanitize strings:
echo $cmd | jq --sanitize
The text was updated successfully, but these errors were encountered:
for example, this is just unacceptably complicated: https://unix.stackexchange.com/a/339892/287203
see my comment to the answer.
Sorry, something went wrong.
I believe the -R option does what you want. The following script:
#!/bin/bash TEXT=$(cat<<"EOF" sed '0,1d' "$HOME/my_bash_history" | wc -l EOF ) echo "TEXT=$TEXT" echo "$TEXT" | jq -R .
produces:
TEXT=sed '0,1d' "$HOME/my_bash_history" | wc -l "sed '0,1d' \"$HOME/my_bash_history\" | wc -l"
thanks let me try it, I wonder if the . is necessary? probably not
.
So, I don't know how to implement a parser for "almost-right" JSON texts like the one you showed us, @ORESoftware...
No branches or pull requests
Here are a couple lines of a JSON in a file:
not quote valid JSON because if you look at the bottom 2 lines, we have this pair:
so what we need is:
my question/request: does/can JQ provide a facility to escape/sanitize strings:
The text was updated successfully, but these errors were encountered: