-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
Describe the bug
In (.[].children|.[])|=if has("color") then . else empty end
, empty
behaves different from regular values.
To Reproduce
Run jq '(.[].children|.[])|=if has("color") then . else empty end' foo.json
, where foo.json is:
[
{
"name": "foo",
"children": [{
"name": "foo.0",
"color": "red"
}]
},
{
"name": "bar",
"children": [{
"name": "bar.0",
"color": "green"
},
{
"name": "bar.1"
}]
},
{
"name": "baz",
"children": [{
"name": "baz.0"
},
{
"name": "baz.1"
}]
}
]
Output:
[
{
"name": "foo",
"children": [
{
"name": "foo.0",
"color": "red"
}
]
},
{
"name": "bar",
"children": [
{
"name": "bar.0",
"color": "green"
}
]
},
{
"name": "baz",
"children": [
{
"name": "baz.1"
}
]
}
]
Expected behavior
I expected this output, which I can get by running del(.[].children[] | select(has("color") | not))
.
[
{
"name": "foo",
"children": [
{
"name": "foo.0",
"color": "red"
}
]
},
{
"name": "bar",
"children": [
{
"name": "bar.0",
"color": "green"
}
]
},
{
"name": "baz",
"children": []
}
]
Environment (please complete the following information):
- OS and Version: macOS Monterey (M1 architecture)
- jq version 1.6