Skip to content

jq stops printing strings converted to number after first conversion fails #2406

Closed
@thalman

Description

@thalman

Jq stops converting strings to numbers on first conversion failure.

To Reproduce
jq '.[]| tonumber?' <<< '["1", "invalid2", "3"]'

Expected behavior
Expected output (works with 1.5):
1
3

jq 1.6 output ("3" is missing)
1

Environment:

  • OS and Version: Linux Fedora 35 (but I believe it is on all platforms)
  • jq version 1.6

Additional context
Only string conversion is affected. The iteration actually continues and if there are following numbers, they are printed

jq '.[]| tonumber?' <<< '["1", "invalid2", "3", 4]'
1
4
^^^ 3 is missing, but 4 is printed

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions