jsonjq

Parse error when text is split on multi lines: "control characters from U+0000 through U+001F must be escaped"


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?


Solution

  • That's because the JSON format is invalid. It should look like this:

    {
        "words" : "one two \nthree four five"
    }