Replies: 1 comment 4 replies
-
Basically it's operator precedence rules, same as you have when evaluating a maths expression like 3 + 4 x 2 = 3 + ( 4 x 2). You multiply before adding. The first expression is evaluated like this:
The second expression is evaluated like this:
Hope that clears things up - TLDR - use brackets to make sure you get want you want in complex expressions. I have tried to make the precedence rules as intuitive as possible, and mimic what jq does. The numbers aren't in the user docs yet, but if you are interested you can see them here: https://github.com/mikefarah/yq/blob/master/pkg/yqlib/lib.go |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I think there's something about the "data model" of
yq
that I'm not understanding, and maybe someone can shed some light on it?I'm trying to understand why these two pipelines give different results:
I expected the same results in both cases, but it seems like select doesn't actually remove the things it's filtering away until it gets to the pipe operator? Like select makes them temporarily
null
, and then the|
actually removes them from the array entirely? Except that's clearly not right, because an array of literalnull
s survives the pipe operator without issue.Can someone explain why these work differently?
(Also
.[] | select(.name=="foo").app_version | . // 0
, which gives the same results as attempt 2, begs an explanation)Beta Was this translation helpful? Give feedback.
All reactions