Skip to content

Filter inputs away #5

@stroan

Description

@stroan

I might well be reading the docs wrong, but I don't think there's a way to perform the following operation. Given the input

{"foo": "bar", "baz": 10}
{"foo": "blap", "baz": 11}
{"foo": "bar", "baz": 12}

Get only the objects where .foo == "bar", resulting in the output:

{"foo": "bar", "baz": 10}
{"foo": "bar", "baz": 12}

Currently the syntax for conditionals, requires an else case. If this were changed to allow only an if case and to not output a value if the case that doesn't match then the program which supplies the above could be:

./jq 'if .foo == "bar" then . end'

My current work around involves using the else case to output a sentinel value which I grep away before piping back into jq again.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions