Problem parsing scalar with leading newline from JSON #2203
Description
Version 4.44.5
Command: echo '{"a": "\nb\nc"}' | yq -p json '.'
Output:
a:2-
b
c
Strange looking scalar (2-
) ... I would have expected |-
or I guess even |2-
. I didn't know this was valid syntax. Maybe it isn't?
Anyway, if I continue this example:
Command: echo '{"a": "\nb\nc"}' | yq -p json '.' | yq '.'
Output:
a: |-
b
c
Looks more like what I would have expected in the first example, though the leading newline has been lost. But it seems broken that the output from the first yq
is different from the second, even though the second is doing nothing more than echoing it.
I can get the same result using an input file (called test.yaml
) that looks like this:
a: |-
b
c
Command: cat test.yaml | yq -o json '.'
Output:
{
"a": "\nb\nc"
}
Command: cat test.yaml | yq -o json '.' | yq -p json '.'
Output:
a:2-
b
c
Command: cat test.yaml | yq -o json '.' | yq -p json '.' | yq '.'
Output:
a: |-
b
c