Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,12 @@ static jv f_tonumber(jq_state *jq, jv input) {
jv_free(input);
return number;
}
if (jv_get_kind(input) == JV_KIND_FALSE) {
return jv_number(0);
}
if (jv_get_kind(input) == JV_KIND_TRUE) {
return jv_number(1);
}
return type_error(input, "cannot be parsed as a number");
}

Expand Down
4 changes: 2 additions & 2 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -2038,8 +2038,8 @@ null
2

.[] |= try tonumber
["1", "2a", "3", " 4 ", "5.67", ".89", "-876", "+5.43", 21]
[1, 3, 5.67, 0.89, -876, 5.43, 21]
["1", "2a", "3", " 4 ", "5.67", ".89", "-876", "+5.43", 21, true, false]
[1, 3, 5.67, 0.89, -876, 5.43, 21, 1, 0]

# Also 1859, but from 2073
any(keys[]|tostring?;true)
Expand Down
4 changes: 2 additions & 2 deletions tests/man.test

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.