⏱️ Timestamps: 00:00 | Intro 00:30 | What we are going to learn? 01:10 | Calling openlibrary.org Search API with curl 02:23 | Using object/value iterator 02:51 | Transforming input JSON to the desired format 03:43 | Filtering null values with the select function 04:23 | Sorting an array by the specific field using sort_by(expr) 05:46 | Limiting the number elements using limit(n;expr) 06:48 | Grouping elements by the specific field using group_by(expr) 09:22 | End screen
I agree. I read through the documentation for jq over and over and tested for hours. This example just made it click and solved a problem that I have been working on all day that had a very simple solution. Amazing job! Thanks for posting!
Fantastic! The best jq intro in the universe! It's almost as if all the articles, tutorials, docs, and etc, were condensed in 9m44s. Thanks for sharing your knowledge!
jq is definitely a godsend; I recently moved parts of my application pipeline to a series of jq processes and life couldn't be peaceful. Thanks for the video, Szymon. With the limit operator, (at least with v1.6), there is another nice way to do it too - "| .[0:n]". Coming from a Python background, this looks easier to comprehend like the slice operation and lesser characters too.
Thank you so much for your kind words, Soham! I hope it will start growing faster when I come back with the new videos in some near future :) Take care, and have a good day!
Thanks !, Yus I do believe it will grow , RUclips’s a weird engine , one day you have a few thousand subs then suddenly you get into 50k+ , your content is a lot better than a ton of 200-300k+ programming youtuber’s I’ve shared some of your videos with my friends too , I’m confident you’ll be much more popular soon . Have a great day !
Fantastic!! 👏🏼👏🏼 I learnt more in this video than I did in my two years of dev experience where I used JQ here and there by skimminging through the documentation examples for a particular use-case of mine.
Thank you so much for your kind words, Himalaya! It is very motivating to hear I was able to pack a lot of useful information to this short video :) Have a good day!
Loved this (and the others in the series), thank you. Nice production, good length, informative. And kudos for using values other than English in the sample data - that was a bonus to me.
I have always found your video helpful when I need to work with jq. I always refer them. I have a request to make if you can do a tutorial of using regular expression with jq. That would be awesome.
Very thorough explanation of JQ! Great work🔥Could you please let me know, how did you screen-share and also your camera? Did you use Zoom or some other software to record yourself while screen sharing. Thanks in advance!
Thanks for your kind words, Sachin! My workflow is not the easiest one - I use a camera to record myself and I record screen separately using OBS. Then I edit it in Adobe Premiere. If you're looking for a tool that does both things at once, you might check Loom (or its alternatives.) I don't use it personally, but I've seen good results from other people and it looks like it is super easy to use. Good luck, and have a good day!
@@szymonstepniak I really like the quality of your video production! Thank you so much for sharing your workflow, it is quite complex. Also, thank you for letting me know about loom, I'll check it out. You too have a great day!
Hi Szymon, While trying to convert the filtered json output to array I am getting issues like all the data is coming in a separate array. My requirement is to get the count of a particular query. I saw your lesson and thought of using the length function but while trying to convert it into an array I am getting all the blanks array. Could you please help. Thanks for the wonderful lessons.
Hi Mohammed, do you have any example I could take a look on? You can use jqplay.org to share what the input JSON looks like and the code you are having problems with.
Question: I have a json file which contains array of json. My objective is to parse that array of json and use each element as data in a curl req. For that i am writing a shell script and using "for" loop. but for some reason, output from jq parser for every iteration is not the json obj but each and every character within that json obj. For eg: if i try to parse "{"A":"B"}, the result would be : 1st iteration - {, 2nd iteration - "A:", 3rd iteration - "B", 4th iteration:}
Hi Devashish! I don't have out-of-the-box solution to your problem. It looks like your shell script uses a string to iterate using for-loop, which would explain the output you get. I would suggest using jq to extract a raw value from the JSON documents you want to pass to the curl command, so you end up with an output that contains each expected value separated by the new line, and then use for-loop to iterate over elements using a new line character as a separator (google something like "bash for loop new line"). Good luck!
Thanks for your kind words, Bui! The "-r" option stands for the "raw output". By default, jq filters serialize output with the JSON format, which means that e.g. every string is wrapped with double quotes. You can turn of this behavior with the "-r" option.
@@szymonstepniak Merry Christmas! I appreciated your reply. I have the API endpoins below: curl -X GET "api.nsone.net/v1/zones" | jq -r ".[].zone" Outputs: hailee.tk haileeduong.net testduong.vn for zone in $(curl -X GET "api.nsone.net/v1/zones" | jq -r ".[].zone"); do curl -X GET "api.nsone.net/v1/stats/qps"; done Outputs: {"qps":52.0} {"qps":13.0} {"qps":7.0} But i want the outputs format like below: ZONE,QPS hailee.tk,{"qps":52.0} haileeduong.net,{"qps":13.0} testduong.vn,{"qps":7.0} So what should i add into the command? Love to hear advices.
If it works for you - feel free to do it. I tried replacing wrapping the whole expressions with the square brackets with the limit from your comment, but it didnt work for me. Take care, and have a good day!
Hi Szymon, I have a work requirement on JQ for which I can pay. I need your consultancy on the same. Please let me know if you are interested. My team is getting stuck with the task they are doing and they are involving PHP to do a certain set of tasks and then use JQ, I think JQ can alone do everything.
Hi Nitin! Thanks for your kind words. I don't take any consultancy gigs at the moment due to limited time. I hope you can find a good solution to your problem based on the available jq user guides and tutorials. Good luck, and have a good day!
Really well presented, thank you! Is it possible to merge the values of 2 fields and join them with a character but only if there is a certain field present? e.g. I only want to join the Series Name and Episode Name of the TV show as one value, but the Movie Name only has one value on its own... {"SeriesName":"The Adventures of Tintin","Name":"The Secret of the Unicorn (1)"} {"Name":"Guardians of the Galaxy"} ...becomes.. {"title":"The Adventures of Tintin / The Secret of the Unicorn (1)"} {"title":"Guardians of the Galaxy"} So far, I have this command line... jq -c '.[].NowPlayingItem | {SeriesName, Name} | select(.Name != null) | {title: (.SeriesName + " / " + .Name)}' emby_sessions.json ...which gives me the WRONG output (see the extra " / " ?) ... {"title":"The Adventures of Tintin / The Secret of the Unicorn (1)"} {"title":" / Guardians of the Galaxy"} Thanks :-)
Thanks for your kind words, Paul! Regarding your question, you can use if-then-else when you construct your final title field. In this case, you can replace: {title: (.SeriesName + " / " + .Name)} with something like this: {title: ((if .SeriesName then .SeriesName + " / " else "" end) + .Name)} and it should work as you expect. Hope it helps. Have a good day!
@@szymonstepniak omg, you star - absolute genius... it works perfectly! I have added it to the Emby Forum thread page and given you a thanks :-) emby.media/community/index.php?/topic/91982-username-nowplayingitemname-for-influxdb-and-grafana/&do=findComment&comment=952656
⏱️ Timestamps:
00:00 | Intro
00:30 | What we are going to learn?
01:10 | Calling openlibrary.org Search API with curl
02:23 | Using object/value iterator
02:51 | Transforming input JSON to the desired format
03:43 | Filtering null values with the select function
04:23 | Sorting an array by the specific field using sort_by(expr)
05:46 | Limiting the number elements using limit(n;expr)
06:48 | Grouping elements by the specific field using group_by(expr)
09:22 | End screen
This video is one of the best things RUclips has to offer. Excellent ratio of information per minute. Thank you so much
Thank you very much for your kind words, Paweł! It's always a very motivating thing to hear. Take care and have a good day!
I agree. I read through the documentation for jq over and over and tested for hours. This example just made it click and solved a problem that I have been working on all day that had a very simple solution. Amazing job! Thanks for posting!
Thank you for creating an example with some complex json that’s easy to understand and helps folks learn
Thank you for your kind words! Take care, and Happy New Year!
Очень доходчиво! Спасибо!
Thank you! Take care, and have a good day!
My coworker suggested you for some Groovy vids and now I’m binging the rest of yours. Thanks for the great quality content, keep it up!
Oh man, I'm grateful for your binge watching session - it's the best thing a content creator can hear. Thank a lot! Take care, and have a good day!
Every secodnis pure gol. thanks for this wonderful video
Thank you so much for your kind words! Take care, and have a good day!
exactly what I was looking for. Thank you!
Thank you! Take care, and have a good day!
Fantastic! The best jq intro in the universe! It's almost as if all the articles, tutorials, docs, and etc, were condensed in 9m44s. Thanks for sharing your knowledge!
Thanks for your kind words, Jose! I plan to publish a few more videos explaining jq, so stay tuned! Have a good day!
Excellent, concrete and useful examples
Glad you like them!
Thanks for the FULL examples. Most only show pieces.
Glad you liked it! Take care, and have a good day!
Wow, that's jq on steroids. Magic!!
Thanks, Karla! Take care, and have a good day!
Very practical!! Thanks
Thanks for your kind words! Take care, and have a good day!
jq is definitely a godsend; I recently moved parts of my application pipeline to a series of jq processes and life couldn't be peaceful. Thanks for the video, Szymon.
With the limit operator, (at least with v1.6), there is another nice way to do it too - "| .[0:n]". Coming from a Python background, this looks easier to comprehend like the slice operation and lesser characters too.
Couldn't agree more, Sriram! Thanks for the valuable comment. Take care, and have a good day!
Owing to this series, I used JQ to do some cool things in my day-to-day work tasks. Would be great to see next part!
Working on a script. Coming soon! :)
Such a great group of lessons, thank you for making these! They're so well done!
Thank you for your kind words! Have a good day!
Loved your video ! ,
Good luck to your channel !
May it grow a ton
Thank you so much for your kind words, Soham! I hope it will start growing faster when I come back with the new videos in some near future :) Take care, and have a good day!
Thanks !,
Yus I do believe it will grow , RUclips’s a weird engine , one day you have a few thousand subs then suddenly you get into 50k+ , your content is a lot better than a ton of 200-300k+ programming youtuber’s I’ve shared some of your videos with my friends too , I’m confident you’ll be much more popular soon .
Have a great day !
Я жду продолжения✌️
Dude, what I needed, real examples. I appreciate you taking the time to share.
Thanks for your kind support! Take care, and have a good day!
Fantastic!! 👏🏼👏🏼 I learnt more in this video than I did in my two years of dev experience where I used JQ here and there by skimminging through the documentation examples for a particular use-case of mine.
Thank you so much for your kind words, Himalaya! It is very motivating to hear I was able to pack a lot of useful information to this short video :) Have a good day!
Great lessons!
Thank you for your kind words, Michal! Take care, and have a good day!
Loved this (and the others in the series), thank you. Nice production, good length, informative. And kudos for using values other than English in the sample data - that was a bonus to me.
Thanks for your kind words, DJ! I'm glad to hear you liked the exotic part of it :) Take care, and have a good day!
Very handy 😆 Thank you so much!
Glad to hear it was helpful for you, Ivan! Take care, and have a good day!
Great informative video for beginners. Awesome !!!
Thanks for your kind words, Deepam! Have a good day!
Woww, thanks for this jq series, really amazing!! 👏👏👏
Thanks for your kind words, Rodrigo! Glad you enjoy it! :-) Have a good day!
Really nice and informative series. Please continue. Thx
Thanks for your kind words, Shawn! Have a good day!
Amazing video you made! Learned a lot😃
Glad it was helpful! Have a good day!
I have always found your video helpful when I need to work with jq. I always refer them.
I have a request to make if you can do a tutorial of using regular expression with jq. That would be awesome.
Thanks for your kind words and the suggestion 👍 I have to create some more jq related videos soon. Take care, and have a good day!
Awesome content man!
Thanks for your kind words, Tejesh! There will be more jq related videos published soon, so stay tuned!
just amazing thank you
Glad you enjoyed it!
Muchas Gracias, excelente explicación.
Thanks, Ronald! I'm glad you find it useful!
Cześć ,samo mięcho , dzięki !
Dzięki wielkie za ciepłe słowa :) Miłego dnia!
Very thorough explanation of JQ! Great work🔥Could you please let me know, how did you screen-share and also your camera? Did you use Zoom or some other software to record yourself while screen sharing. Thanks in advance!
Thanks for your kind words, Sachin! My workflow is not the easiest one - I use a camera to record myself and I record screen separately using OBS. Then I edit it in Adobe Premiere. If you're looking for a tool that does both things at once, you might check Loom (or its alternatives.) I don't use it personally, but I've seen good results from other people and it looks like it is super easy to use. Good luck, and have a good day!
@@szymonstepniak I really like the quality of your video production! Thank you so much for sharing your workflow, it is quite complex. Also, thank you for letting me know about loom, I'll check it out. You too have a great day!
Great video bro, I'm trying it out with kubernetes objects
Good luck! I hope jq does the job for you :) Take care, and have a good day!
Enjoying your videos. Subscribed.
Welcome aboard, Jay, and thanks for the kind words! Have a good day! :)
Hi Szymon,
While trying to convert the filtered json output to array I am getting issues like all the data is coming in a separate array. My requirement is to get the count of a particular query. I saw your lesson and thought of using the length function but while trying to convert it into an array I am getting all the blanks array. Could you please help. Thanks for the wonderful lessons.
Hi Mohammed, do you have any example I could take a look on? You can use jqplay.org to share what the input JSON looks like and the code you are having problems with.
Question: I have a json file which contains array of json. My objective is to parse that array of json and use each element as data in a curl req. For that i am writing a shell script and using "for" loop. but for some reason, output from jq parser for every iteration is not the json obj but each and every character within that json obj. For eg: if i try to parse "{"A":"B"}, the result would be : 1st iteration - {, 2nd iteration - "A:", 3rd iteration - "B", 4th iteration:}
Hi Devashish! I don't have out-of-the-box solution to your problem. It looks like your shell script uses a string to iterate using for-loop, which would explain the output you get. I would suggest using jq to extract a raw value from the JSON documents you want to pass to the curl command, so you end up with an output that contains each expected value separated by the new line, and then use for-loop to iterate over elements using a new line character as a separator (google something like "bash for loop new line"). Good luck!
which font do you use in the terminal? It looks good
The font I use is Source Code Pro Medium, size 12. Have a good day! :)
Thanks for your helpful video. Could you please tell me jq -r means?
Thanks for your kind words, Bui! The "-r" option stands for the "raw output". By default, jq filters serialize output with the JSON format, which means that e.g. every string is wrapped with double quotes. You can turn of this behavior with the "-r" option.
@@szymonstepniak Merry Christmas! I appreciated your reply. I have the API endpoins below:
curl -X GET "api.nsone.net/v1/zones" | jq -r ".[].zone"
Outputs:
hailee.tk
haileeduong.net
testduong.vn
for zone in $(curl -X GET "api.nsone.net/v1/zones" | jq -r ".[].zone"); do curl -X GET "api.nsone.net/v1/stats/qps"; done
Outputs:
{"qps":52.0}
{"qps":13.0}
{"qps":7.0}
But i want the outputs format like below:
ZONE,QPS
hailee.tk,{"qps":52.0}
haileeduong.net,{"qps":13.0}
testduong.vn,{"qps":7.0}
So what should i add into the command?
Love to hear advices.
is it okay to just add '| [limit(99999)] ' instead of wrapping whole thing with squre bracket?
If it works for you - feel free to do it. I tried replacing wrapping the whole expressions with the square brackets with the limit from your comment, but it didnt work for me. Take care, and have a good day!
Hi Szymon, I have a work requirement on JQ for which I can pay. I need your consultancy on the same. Please let me know if you are interested. My team is getting stuck with the task they are doing and they are involving PHP to do a certain set of tasks and then use JQ, I think JQ can alone do everything.
Hi Nitin! Thanks for your kind words. I don't take any consultancy gigs at the moment due to limited time. I hope you can find a good solution to your problem based on the available jq user guides and tutorials. Good luck, and have a good day!
how to get the values in one line like output should be title, author_name, ..
how did you do it can you share with me , thank you
Really well presented, thank you!
Is it possible to merge the values of 2 fields and join them with a character but only if there is a certain field present?
e.g.
I only want to join the Series Name and Episode Name of the TV show as one value, but the Movie Name only has one value on its own...
{"SeriesName":"The Adventures of Tintin","Name":"The Secret of the Unicorn (1)"}
{"Name":"Guardians of the Galaxy"}
...becomes..
{"title":"The Adventures of Tintin / The Secret of the Unicorn (1)"}
{"title":"Guardians of the Galaxy"}
So far, I have this command line...
jq -c '.[].NowPlayingItem | {SeriesName, Name} | select(.Name != null) | {title: (.SeriesName + " / " + .Name)}' emby_sessions.json
...which gives me the WRONG output (see the extra " / " ?) ...
{"title":"The Adventures of Tintin / The Secret of the Unicorn (1)"}
{"title":" / Guardians of the Galaxy"}
Thanks :-)
Thanks for your kind words, Paul! Regarding your question, you can use if-then-else when you construct your final title field. In this case, you can replace:
{title: (.SeriesName + " / " + .Name)}
with something like this:
{title: ((if .SeriesName then .SeriesName + " / " else "" end) + .Name)}
and it should work as you expect. Hope it helps. Have a good day!
@@szymonstepniak omg, you star - absolute genius... it works perfectly! I have added it to the Emby Forum thread page and given you a thanks :-)
emby.media/community/index.php?/topic/91982-username-nowplayingitemname-for-influxdb-and-grafana/&do=findComment&comment=952656
@Paul Littlefield Cowabunga, thanks! ☺️ I'm glad I was able to help you. Good luck and have a good day! 👍
Helga Mills
Helga is cool 👍