Skip to content

London | 25-SDC-Nov | Jesus del Moral | Sprint 2 | JQ#231

Open
delmorallopez wants to merge 2 commits intoCodeYourFuture:mainfrom
delmorallopez:jq
Open

London | 25-SDC-Nov | Jesus del Moral | Sprint 2 | JQ#231
delmorallopez wants to merge 2 commits intoCodeYourFuture:mainfrom
delmorallopez:jq

Conversation

@delmorallopez
Copy link

@delmorallopez delmorallopez commented Nov 17, 2025

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

@github-actions
Copy link

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).

@delmorallopez delmorallopez changed the title London | 25-SDC-Nov | Jesus del Moral | Sprint 1 | Shell pipelines London | 25-SDC-Nov | Jesus del Moral | Sprint 2 | jq Nov 17, 2025
@github-actions
Copy link

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
@github-actions
Copy link

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).

@github-actions
Copy link

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).

@github-actions
Copy link

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).

@github-actions
Copy link

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).

@delmorallopez delmorallopez changed the title London | 25-SDC-Nov | Jesus del Moral | Sprint 2 | jq London | 25-SDC-Nov | Jesus del Moral | Sprint 2 | JQ Nov 17, 2025
@github-actions
Copy link

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).

@github-actions
Copy link

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).

@delmorallopez delmorallopez added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 17, 2025
@github-actions
Copy link

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).

@delmorallopez delmorallopez added the 📅 Sprint 2 Assigned during Sprint 2 of this module label Nov 17, 2025
Copy link

@LonMcGregor LonMcGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@LonMcGregor LonMcGregor added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 25, 2025
@delmorallopez delmorallopez added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 26, 2025
@delmorallopez
Copy link
Author

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

Copy link

@LonMcGregor LonMcGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does wrapping the middle (.scores | length) in brackets here do?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you try running this command without the inner brackets, does it change the output?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see what you mean
I have modified the script to (.scores | length | tostring)
Working fine

@LonMcGregor LonMcGregor removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 1, 2025
@delmorallopez delmorallopez added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 1, 2025
Copy link

@LonMcGregor LonMcGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now!

@LonMcGregor LonMcGregor added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants