Skip to content

auto input setting overrides explicit output setting #2562

@ThorbenJ

Description

@ThorbenJ

Describe the bug
When using yq v4.47.1, specifying -o=yaml for JSON input is ignored if the input format is auto-detected (default or -p=auto), and the output remains JSON. Explicitly setting -p=json works as expected. This does not occur for YAML input to JSON output.

Auto input detection (implicit or explicit with -p=auto) appears to override explicit output (-o=yaml) for JSON input. The output remains JSON, even when YAML is requested.

Installation
Via Nix on MacOS:

which yq
/Users/thorbenj/.nix-profile/bin/yq

yq --version
yq (https://github.com/mikefarah/yq/) version v4.47.1

Reproduce

json to yaml example:
Explicit input and output works:

echo '{"foo": "bar", "baz": [1,2,3]}' | yq -p=json -o=yaml
foo: bar
baz:
  - 1
  - 2
  - 3

Implicit (explicit auto) input does not work:

echo '{"foo": "bar", "baz": [1,2,3]}' | yq -p=auto -o=yaml
{"foo": "bar", "baz": [1, 2, 3]}

echo '{"foo": "bar", "baz": [1,2,3]}' | yq  -o=yaml
{"foo": "bar", "baz": [1, 2, 3]}

Interestingly output json (from yaml) does not have this issue

echo -e "foo: bar\nbaz:\n  - 1\n  - 2\n  - 3" | yq -p=yaml -o=json
{
  "foo": "bar",
  "baz": [
    1,
    2,
    3
  ]
}

echo -e "foo: bar\nbaz:\n  - 1\n  - 2\n  - 3" | yq -p=auto -o=json
{
  "foo": "bar",
  "baz": [
    1,
    2,
    3
  ]
}

echo -e "foo: bar\nbaz:\n  - 1\n  - 2\n  - 3" | yq  -o=json
{
  "foo": "bar",
  "baz": [
    1,
    2,
    3
  ]
}

Expected behaviour

Explicit output format should always be honoured!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions