4 ms·
Works well enough, but it really tripped me up at first with the syntax. Had to constantly look things up while using it. jq -r \ '.apps.http.servers.srv1.
by VoodooJuJu 3y ago
Works well enough, but it really tripped me up at first with the syntax. Had to constantly look things up while using it.
jq -r \
'.apps.http.servers.srv1.routes[0]
| .match[0].header.[env.AUTH_USER_HEADER][0] = "$username"'
That's an error because you can't select an env var key '[env.AUTH_USER_HEADER]' in the middle of a chain like that, only immediately following a pipe:
| .match[0].header | .[env.AUTH_USER_HEADER][0] = "$username"'
But then I need to preserve the parent object after the assignment and that pipe throws it out. Thankfully, parentheses fix that:
| (.match[0].header | .[env.AUTH_USER_HEADER][0]) = "$username"'
After working out the gotchas, it's quite powerful, like regex, but a little clunky, though not nearly as much as regex.
- rewmie 3y ago> Almost feels like I'm learning regex again. But isn't that what jq is and always has been? I mean,what led you to believe that an entirely unrelated pattern matching language would work?
- cryptonector 3y ago> jq -r \ > '.apps.http.servers.srv1.routes[0] > | .match[0].header.[env.AUTH_USER_HEADER][0] = "$username"' > That's an error because you can't select an env var key '[env.AUTH_USER_HEADER]' in the middle of a chain like that, only immediately following a pipe: > | .match[0].header | .[env.AUTH_USER_HEADER][0] = "$username"' You can use `env.AUTH_USER_HEADER` as a key the way you wanted. The issue is that you had to write `... | .match[0].header[env.AUTH_USER_HEADER] ...` -- no `.` between "header" and the index operator! This complaint is a fairly frequent one, so in fact we did "fix" this in 1.7! You can now write `.a.[0]` and it works.
- deleted 3y ago[deleted]