Skip to content
New issue

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

Problem parsing scalar with leading newline from JSON #2203

Open
corporatemodelling opened this issue Nov 25, 2024 · 0 comments
Open

Problem parsing scalar with leading newline from JSON #2203

corporatemodelling opened this issue Nov 25, 2024 · 0 comments
Labels

Comments

@corporatemodelling
Copy link

corporatemodelling commented Nov 25, 2024

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
@corporatemodelling corporatemodelling changed the title Problem parsing scalar from JSON Problem parsing scalar with leading newline from JSON Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant