-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
select does not eliminate all mismatches #2422
Comments
Hi, I think you might be hitting the same issue as in #2051. A workaround could be something like: .project.channels |= map(select(."cVal" == "South")) |
The seemingly strange behavior of This aspect of (@itchyny - Perhaps the "bug" label should be changed? An ER for functionality? Documentation?) |
I suggest using I don't think it ever makes sense to "prefer" Both of |
Ah, right, if you expect |
@nicowilliams wrote:
Apparently not, e.g.:
|
Right. So the correct way to fix this (IMO) would be to add something like the |
|
the select function passes through objects that it should filter out
input:
{ "project":{ "channels":[
{ "cName":"c1", "cVal":"North" },
{ "cName":"c2", "cVal":"North" },
{ "cName":"c3", "cVal":"South" },
{ "cName":"c4", "cVal":"North" },
{ "cName":"c5", "cVal":"South" }
] } }
code:
.project.channels[] |= select( ."cVal" == "South")
expected ouput:
{
"project": {
"channels": [
{
"cName": "c3",
"cVal": "South"
},
{
"cName": "c5",
"cVal": "South"
}
]
}
}
actual output
{
"project": {
"channels": [
{
"cName": "c2",
"cVal": "North"
},
{
"cName": "c3",
"cVal": "South"
},
{
"cName": "c5",
"cVal": "South"
}
]
}
}
select failed to eliminate all objects where cVal was not "South"
The behavior seems to be that , if there are two objects in a row that need eliminated, it lets the second one pass .
This could happen if the code was traversing a linked list, testing each node, eliminating a node, then going to next node.
If the code eliminates a node, then the following node will become the current node, so the code should then test the (new) current node before moving on.
The behavior is seen on jqplay.org
(
and also on jq-win64.exe with proper windows quoting
jq-Win64.exe ".project.channels[] |= select( ."""cVal""" == """South""") " my.txt
)
The text was updated successfully, but these errors were encountered: