I'm getting a "parse error" when I split a text line on multiple lines and show the JSON file on screen with the command jq . words.json.
The JSON file with the text value on a single line looks like this
{
"words" : "one two three four five"
}
The command jq . words.json works fine and shows the JSON file on screen.
But when I split the value "one two three four five" on two lines and run the same command I get a parse error
{
"words" : "one two
three four five"
^
}
parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 3, column 20
The parse error points to the " character at the end of the third line.
How can I solve this?
That's not valid JSON; JSON strings don't contain literal newlines. But you can do:
jq -Rnr '[inputs] | join("\\n") | fromjson | .choices[0].message.content' sample.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With