London | 25-SDC-Nov | Jesus del Moral | Sprint 2 | JQ#231
London | 25-SDC-Nov | Jesus del Moral | Sprint 2 | JQ#231delmorallopez wants to merge 2 commits intoCodeYourFuture:mainfrom
Conversation
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
4 similar comments
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
LonMcGregor
left a comment
There was a problem hiding this comment.
Did you mean to make changes to all these files? We try to keep pull requests specific to just the files in the feature we are changing - for this, everything within the jq sprint task. I can't continue reviewing until the PR is made more specific.
|
SDC Sprint 3 | jq exercises Understanding and manipulating JSON. The best way to get to grips with jq is by using it. jq section exercices under Sprint2 |
LonMcGregor
left a comment
There was a problem hiding this comment.
Good work, I just have one comment about some of your JQ commands
jq/script-08.sh
Outdated
| # Your output should contain 6 lines, each with one word and one number on it. | ||
| # The first line should be "Ahmed 3" with no quotes. | ||
|
|
||
| jq -r '.[] | .name + ", " + ((.scores | length) | tostring)' scores.json No newline at end of file |
There was a problem hiding this comment.
What does wrapping the middle (.scores | length) in brackets here do?
There was a problem hiding this comment.
.scores | length, Take the array in .scores and count its elements
( ... ) Treat that whole pipeline as one single value
| tostring, Convert that value (a number) into a string
.name + ", " + , Concatenate everything
So parentheses force jq to evaluate the inner expression first, jq requires grouping when mixing pipelines with string concatenation.
There was a problem hiding this comment.
If you try running this command without the inner brackets, does it change the output?
There was a problem hiding this comment.
running without brackets
jq -r '.[] | .name + ", " + .scores | length' scores.json
got an error
jq: error (at scores.json:1): string ("Ahmed, ") and array ([1,10,4]) cannot be added
That happens because | (pipe) runs after + (string concat)
jq interprets it as: (.name + ", " + .scores) | length
Yes, removing the parentheses changes the output drastically
There was a problem hiding this comment.
Yes, the outer brackets are necessary as you identify. I was focusing on the inner brackets. Piping works always from left to right, so you don't need to wrap them.
i.e.
((.scores | length) | tostring)
gives the same as
(.scores | length | tostring)
Do you see what I mean?
There was a problem hiding this comment.
I can see what you mean
I have modified the script to (.scores | length | tostring)
Working fine
SDC Sprint 3 | jq exercises
Understanding and manipulating JSON. The best way to get to grips with jq is by using it.
jq section exercices under Sprint2