Transforming, sorting, and grouping JSON documents in the command-line - jq tutorial

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 92

  • @szymonstepniak
    @szymonstepniak  4 года назад +4

    ⏱️ 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

  • @paweosmolski5567
    @paweosmolski5567 3 года назад +14

    This video is one of the best things RUclips has to offer. Excellent ratio of information per minute. Thank you so much

    • @szymonstepniak
      @szymonstepniak  3 года назад

      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!

    • @MikeCairns1
      @MikeCairns1 2 года назад

      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!

  • @kossboss
    @kossboss 11 месяцев назад +1

    Thank you for creating an example with some complex json that’s easy to understand and helps folks learn

    • @szymonstepniak
      @szymonstepniak  10 месяцев назад

      Thank you for your kind words! Take care, and Happy New Year!

  • @ДенисКвочка
    @ДенисКвочка Год назад +1

    Очень доходчиво! Спасибо!

    • @szymonstepniak
      @szymonstepniak  Год назад +1

      Thank you! Take care, and have a good day!

  • @Skyler9604
    @Skyler9604 Год назад +1

    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!

    • @szymonstepniak
      @szymonstepniak  Год назад +1

      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!

  • @nilanjansarkar100
    @nilanjansarkar100 Год назад +1

    Every secodnis pure gol. thanks for this wonderful video

    • @szymonstepniak
      @szymonstepniak  Год назад

      Thank you so much for your kind words! Take care, and have a good day!

  • @iamfaze
    @iamfaze 2 года назад +1

    exactly what I was looking for. Thank you!

    • @szymonstepniak
      @szymonstepniak  2 года назад

      Thank you! Take care, and have a good day!

  • @jnetto
    @jnetto 3 года назад +2

    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!

    • @szymonstepniak
      @szymonstepniak  3 года назад

      Thanks for your kind words, Jose! I plan to publish a few more videos explaining jq, so stay tuned! Have a good day!

  • @Hector-Site
    @Hector-Site Год назад +1

    Excellent, concrete and useful examples

  • @conniedave7628
    @conniedave7628 Год назад +1

    Thanks for the FULL examples. Most only show pieces.

    • @szymonstepniak
      @szymonstepniak  Год назад

      Glad you liked it! Take care, and have a good day!

  • @karlastambla2788
    @karlastambla2788 2 года назад +1

    Wow, that's jq on steroids. Magic!!

    • @szymonstepniak
      @szymonstepniak  2 года назад

      Thanks, Karla! Take care, and have a good day!

  • @diegochertoff
    @diegochertoff 2 года назад +1

    Very practical!! Thanks

    • @szymonstepniak
      @szymonstepniak  2 года назад

      Thanks for your kind words! Take care, and have a good day!

  • @sriramvelamur
    @sriramvelamur 3 года назад +2

    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.

    • @szymonstepniak
      @szymonstepniak  3 года назад +1

      Couldn't agree more, Sriram! Thanks for the valuable comment. Take care, and have a good day!

  • @xGorynychx
    @xGorynychx 4 года назад +3

    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!

  • @M1k3M1z
    @M1k3M1z 3 года назад +4

    Such a great group of lessons, thank you for making these! They're so well done!

    • @szymonstepniak
      @szymonstepniak  3 года назад

      Thank you for your kind words! Have a good day!

  • @teitoklien
    @teitoklien 3 года назад +1

    Loved your video ! ,
    Good luck to your channel !
    May it grow a ton

    • @szymonstepniak
      @szymonstepniak  3 года назад +1

      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!

    • @teitoklien
      @teitoklien 3 года назад

      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 !

  • @user-ys4zg4ks7z
    @user-ys4zg4ks7z 3 года назад +1

    Я жду продолжения✌️

  • @CoronaBVW
    @CoronaBVW 2 года назад +1

    Dude, what I needed, real examples. I appreciate you taking the time to share.

    • @szymonstepniak
      @szymonstepniak  2 года назад

      Thanks for your kind support! Take care, and have a good day!

  • @iceadobe139
    @iceadobe139 3 года назад +2

    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.

    • @szymonstepniak
      @szymonstepniak  3 года назад +1

      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!

  • @michalginda387
    @michalginda387 3 года назад +1

    Great lessons!

    • @szymonstepniak
      @szymonstepniak  3 года назад

      Thank you for your kind words, Michal! Take care, and have a good day!

  • @DJAdams
    @DJAdams 3 года назад +1

    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.

    • @szymonstepniak
      @szymonstepniak  3 года назад

      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!

  • @ivanpavlov7101
    @ivanpavlov7101 3 года назад +1

    Very handy 😆 Thank you so much!

    • @szymonstepniak
      @szymonstepniak  3 года назад

      Glad to hear it was helpful for you, Ivan! Take care, and have a good day!

  • @deepambasu9661
    @deepambasu9661 3 года назад +2

    Great informative video for beginners. Awesome !!!

    • @szymonstepniak
      @szymonstepniak  3 года назад

      Thanks for your kind words, Deepam! Have a good day!

  • @RodrigoStuchi
    @RodrigoStuchi 4 года назад +2

    Woww, thanks for this jq series, really amazing!! 👏👏👏

    • @szymonstepniak
      @szymonstepniak  4 года назад +1

      Thanks for your kind words, Rodrigo! Glad you enjoy it! :-) Have a good day!

  • @sjcampbl
    @sjcampbl 3 года назад +1

    Really nice and informative series. Please continue. Thx

    • @szymonstepniak
      @szymonstepniak  3 года назад

      Thanks for your kind words, Shawn! Have a good day!

  • @pfkong6917
    @pfkong6917 3 года назад +1

    Amazing video you made! Learned a lot😃

  • @himanshutank5477
    @himanshutank5477 2 года назад +1

    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.

    • @szymonstepniak
      @szymonstepniak  2 года назад

      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!

  • @tejeshvaish17
    @tejeshvaish17 3 года назад +2

    Awesome content man!

    • @szymonstepniak
      @szymonstepniak  3 года назад

      Thanks for your kind words, Tejesh! There will be more jq related videos published soon, so stay tuned!

  • @pavelow36
    @pavelow36 4 года назад +2

    just amazing thank you

  • @ronaldcastaneda2547
    @ronaldcastaneda2547 4 года назад +1

    Muchas Gracias, excelente explicación.

    • @szymonstepniak
      @szymonstepniak  4 года назад

      Thanks, Ronald! I'm glad you find it useful!

  • @XR5PL
    @XR5PL 3 года назад +1

    Cześć ,samo mięcho , dzięki !

    • @szymonstepniak
      @szymonstepniak  3 года назад

      Dzięki wielkie za ciepłe słowa :) Miłego dnia!

  • @saching9305
    @saching9305 Год назад +1

    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!

    • @szymonstepniak
      @szymonstepniak  Год назад +1

      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!

    • @saching9305
      @saching9305 Год назад

      @@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!

  • @Maica1V
    @Maica1V 2 года назад +1

    Great video bro, I'm trying it out with kubernetes objects

    • @szymonstepniak
      @szymonstepniak  2 года назад

      Good luck! I hope jq does the job for you :) Take care, and have a good day!

  • @j_holtslander
    @j_holtslander 4 года назад +1

    Enjoying your videos. Subscribed.

    • @szymonstepniak
      @szymonstepniak  4 года назад

      Welcome aboard, Jay, and thanks for the kind words! Have a good day! :)

  • @mohammedminhajulhaq5542
    @mohammedminhajulhaq5542 2 года назад +1

    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.

    • @szymonstepniak
      @szymonstepniak  2 года назад

      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.

  • @devashishkhandelwal1009
    @devashishkhandelwal1009 3 года назад +1

    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:}

    • @szymonstepniak
      @szymonstepniak  3 года назад

      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!

  • @shreyash412
    @shreyash412 3 года назад +1

    which font do you use in the terminal? It looks good

    • @szymonstepniak
      @szymonstepniak  3 года назад +1

      The font I use is Source Code Pro Medium, size 12. Have a good day! :)

  • @thuyduong1809
    @thuyduong1809 4 года назад +2

    Thanks for your helpful video. Could you please tell me jq -r means?

    • @szymonstepniak
      @szymonstepniak  3 года назад +2

      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.

    • @thuyduong1809
      @thuyduong1809 3 года назад +1

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

  • @hsjoo1759
    @hsjoo1759 2 года назад +1

    is it okay to just add '| [limit(99999)] ' instead of wrapping whole thing with squre bracket?

    • @szymonstepniak
      @szymonstepniak  2 года назад

      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!

  • @nitinsrivastava7458
    @nitinsrivastava7458 3 года назад +1

    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.

    • @szymonstepniak
      @szymonstepniak  3 года назад

      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!

  • @harishkolanu
    @harishkolanu 3 года назад

    how to get the values in one line like output should be title, author_name, ..

  • @vuha5889
    @vuha5889 3 года назад

    how did you do it can you share with me , thank you

  • @PaulLittlefield
    @PaulLittlefield 4 года назад +1

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

    • @szymonstepniak
      @szymonstepniak  4 года назад

      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!

    • @PaulLittlefield
      @PaulLittlefield 4 года назад +1

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

    • @szymonstepniak
      @szymonstepniak  4 года назад

      @Paul Littlefield Cowabunga, thanks! ☺️ I'm glad I was able to help you. Good luck and have a good day! 👍

  • @EdwardTucker-h6q
    @EdwardTucker-h6q Месяц назад

    Helga Mills