Merging JSON documents in the command-line - jq tutorial

  Рет қаралды 23,028

Szymon Stepniak

Szymon Stepniak

Күн бұрын

Пікірлер: 51
@J3rs3yM1k3
@J3rs3yM1k3 3 жыл бұрын
I would love to see more of these.
@szymonstepniak
@szymonstepniak 3 жыл бұрын
Challenge accepted! :) Take care and have a good day!
@gitgosc7075
@gitgosc7075 Жыл бұрын
wspaniała seria o jq, najwyższa jakość! Ogladanie tego to czysta przyjemność - chętnie zobaczyłbym podobna serię na temat narzędzia AWK. Doceniam ten ogrom pracy - nawet gdyby oprawa video była na niższym poziomie to dalej byłby topowy materiał ze względu na treść i przekaz!
@szymonstepniak
@szymonstepniak Жыл бұрын
Dziękuję za ciepłe słowa, @GitGość! I dzięki za sugestię dotyczącą AWK - nie czuję się ekspertem w tym temacie, ale może przy okazji opracowywania materiału video udałoby mi się trochę podszlifować AWK-a :) Trzymaj się, miłego dnia!
@obiwankenobe3962
@obiwankenobe3962 2 жыл бұрын
Szacun za super prezentacje (mam na mysli wszystkie odciniki). Swietnie intro do jq, dzieki!
@szymonstepniak
@szymonstepniak 2 жыл бұрын
Dzięki wielkie za ciepłe słowa! Trzymaj się, miłego dnia!
@horizonlimit89
@horizonlimit89 4 жыл бұрын
this is next level jq stuff! Ming Boggling :)
@szymonstepniak
@szymonstepniak 4 жыл бұрын
Thanks for your kind words, Shitiz! Have a good day!
@edwardishaq
@edwardishaq 3 жыл бұрын
Wow, I never knew about all this stuff. Amazing JQ skills
@szymonstepniak
@szymonstepniak 3 жыл бұрын
Thanks!
@kyoungjinkim6394
@kyoungjinkim6394 2 жыл бұрын
Great... thank you so much ~~~
@szymonstepniak
@szymonstepniak 2 жыл бұрын
Welcome 😊
@joanestradaramos1541
@joanestradaramos1541 2 жыл бұрын
AMAZING
@szymonstepniak
@szymonstepniak Жыл бұрын
Thank you, Joan! Take care, and have a good day!
@conor7083
@conor7083 3 жыл бұрын
потрясающе! спасибо!
@ering2898
@ering2898 3 жыл бұрын
very helpful ! want to see more examples
@szymonstepniak
@szymonstepniak 3 жыл бұрын
Thanks Erin! Have a good day!
@AllanKobelansky
@AllanKobelansky 3 жыл бұрын
Very good production value and content. Would you consider pausing for a few more seconds after you type the last character of a command? The transition from completing a command to hitting return is about 2-3 milliseconds. Also, would you consider putting the commands and the files in the comment section? I've subscribed.
@szymonstepniak
@szymonstepniak 3 жыл бұрын
Thanks for your kind words, Allan! You're right - making pause for a few seconds before hitting the enter key would improve the user experience. I also plan to supplement upcoming videos with dedicated GitHub repo with all code samples and extra information. The video format has one significant downside - once it published, it cannot be edited. The external repo can help with keeping the information up-to-date, and it allows to add some extra information in future when needed. Thanks a lot for the very valuable input! Take care, and have a good day!
@delio_pl
@delio_pl 4 жыл бұрын
Nice video. I have learnt much from this. I wonder if jq could be used to merge 2 objects that have complex type fields on the second level, third level and so on. Your solution seems to recognize field type (array/object) only on the first level. It may be my proposal of topic for the next part of this course ;) Thank You.
@delio_pl
@delio_pl 4 жыл бұрын
I needed this solution to merge 'bookmarks' from my two browsers. Here is my code written in JavaScript pastebin.com/0zngrjqr
@szymonstepniak
@szymonstepniak 4 жыл бұрын
That's an excellent point, thanks! The example I show in the video can be extended to support deep merge behavior by using a recursive function. Take a look at this example: gist.githubusercontent.com/wololock/238d7afe37808eaa3252cc09a4421b0f/raw/885d4a02b6e999167a19cbc7757cebb79b6f33e0/deepmerge.sh Here I extracted a function "f" that handles reducing a list of objects into a single object by merging key-value pairs. Whenever it spots that the type of a value on the right side is "object", it calls itself recursively on a list constructed from the .[$key] (left-side value) and the $val (right-side value). It's not very sophisticated, and it assumes that the same keys store the same type of value, so if you run into a problem like a["foo"] is an object but b["foo"] is an array, you may have to extend the if-conditions to take both types into account to handle it correctly. Hope it helps. Have a good day!
@silent-ghost
@silent-ghost 2 жыл бұрын
Hi Szymon, thank you so much for your guides. I was wondering if you could continue your JQ playlist and maybe include data explaration queries like max size of properties for example. So many times I had Azure fail due to values exceeding the target defined size but I had no ideea what column to adjust. Thank you so much!
@szymonstepniak
@szymonstepniak 2 жыл бұрын
Thank you for your kind words, Vlad! And thanks for sharing ideas for more JQ related videos - I have a few in mind that I plan to record soon. I think adding a few more short and useful videos explaining some day-to-day tasks would be useful for the community. Stay tuned, and have a good day!
@dayasagareddya.c.9547
@dayasagareddya.c.9547 3 жыл бұрын
Impressive stuff it saves writing alot of code.observation the final query was working fine if I have an object 1 level deeper if it's at 2 level deeper merge was not working as expected.
@szymonstepniak
@szymonstepniak 3 жыл бұрын
Yes, this is shallow merge. I explained recursive merge in this blog post - e.printstacktrace.blog/merging-json-files-recursively-in-the-command-line/ :)
@dayasagareddya.c.9547
@dayasagareddya.c.9547 3 жыл бұрын
@@szymonstepniak works like a magic..thank you.
@aceninopis-an5336
@aceninopis-an5336 2 жыл бұрын
Hello,may i ask on what application are you using in the video?, I'm still new to these things
@szymonstepniak
@szymonstepniak 2 жыл бұрын
I use Linux + ZSH shell + oh-my-zsh + Guake (terminal). Take care, and have a good day!
@sudosnoop
@sudosnoop 3 жыл бұрын
+1 👍
@TJ-hs1qm
@TJ-hs1qm 2 жыл бұрын
It would be nice to also tag the source of a particular attribute in the final output ... subbed 🙂 Have looked into CRDTs ?
@szymonstepniak
@szymonstepniak 2 жыл бұрын
Thanks for the suggestion! 👍 Nope, I haven't looked at CRDTs. Is it related to the video? Take care, and have a good day!
@riteshm7466
@riteshm7466 2 жыл бұрын
Szymon, Is there a way where we can use jq to compare 2 json files (only particular key:value) and give the diff of that?
@szymonstepniak
@szymonstepniak 2 жыл бұрын
I'm not sure if you can use jq to compare two JSON files, but there is a way to use it in combination with the diff command. I can imagine that you have two JSON files that have a different order of fields you want to compare. I would do it in 3 steps: 1. Use jq to extract fields you want to compare in a specific order from the first JSON file and put the result in a new file (e.g. file_1.json) 2. Use jq to extract fields you want to compare in a specific order from the second JSON file and put the result in a new file (e.g. file_2.json) 3. Check the diff between the two files (e.g. diff file_1.json file_2.json) There might be an other way to do a similar thing, but I think this one is simple and straightforward. Good luck, and have a good day!
@soundofmusic94
@soundofmusic94 3 жыл бұрын
hi man, thanks for your video. Question , how can I do this for a N number of json files, and inside every file is an array of objects?
@szymonstepniak
@szymonstepniak 3 жыл бұрын
You should be able to do something like that based on this example. You can pass multiple JSON files as an input to the jq command (e.g. file-*.json pattern can match files like file-01.json, file-02.json etc.) As for the JSON document containing an array of objects - I don't have an out-of-the-box example, but I guess you can experiment a bit and come up with a good solution. Good luck, and have a good day!
@kashyapkiran1729
@kashyapkiran1729 4 жыл бұрын
nice video. can you make some videos of make file
@szymonstepniak
@szymonstepniak 4 жыл бұрын
Thanks for the comment, Kashyap! Could you give me some more context? Do you mean a video on Makefile? Thanks in advance and have a good day!
@kashyapkiran1729
@kashyapkiran1729 4 жыл бұрын
@@szymonstepniak yes Makefile
@szymonstepniak
@szymonstepniak 4 жыл бұрын
@@kashyapkiran1729 Hmm, I don't say "No", but I can't say "Yes" either, because I don't use Makefiles at all. If something changes in this area and I will find creating a video about helpful, I will definitely do it. Thanks for the suggestion, Kashyap! Have a good day!
@xettabyte1
@xettabyte1 2 жыл бұрын
pretty much amazing video sir, where can I send a Dm?
@szymonstepniak
@szymonstepniak 2 жыл бұрын
Hi Ariful Anik, what type of question would you like to ask?
@xettabyte1
@xettabyte1 2 жыл бұрын
@@szymonstepniak about merging json file sir
@szymonstepniak
@szymonstepniak 2 жыл бұрын
@@xettabyte1 Feel free to ask it here. If I won't be able to help you, maybe someone else will.
@JohnOlat
@JohnOlat 11 ай бұрын
This was helpful, I have two json file Product and Prices which I got from post man. How do I merge them? The both have same Product: Bag SimpleCode#10290 Price: $100 SimpleCode#10290 How do I merge?
@cya3mdirl158
@cya3mdirl158 4 жыл бұрын
No to use on production
@szymonstepniak
@szymonstepniak 4 жыл бұрын
Thanks for your comment, CamiL. Have a good day!
@salazar2287
@salazar2287 2 жыл бұрын
too long
@szymonstepniak
@szymonstepniak 2 жыл бұрын
Thanks for your feedback! I hope you could still learn something useful from that video. Take care, and have a good day!
@conor7083
@conor7083 3 жыл бұрын
how i can merge only two arrays. f.e. prices and tags? jq -s '.[0] as $a | .[1] as $b | $a * $b | .prices = $a.prices + $b.prices | .tags = $a.tags+ $b.tags' firstfile.json results.json - merge and another arrays.
@conor7083
@conor7083 3 жыл бұрын
jq -s 'reduce .[] as $item ({}; reduce ($item | keys_unsorted[]) as $key (.; $item[$key] as $val | ($val | type) as $type | .[$key] = if($key == "prices") or ($key == "tags") then (.[$key]+$val) else {} end ))' *.json and another objects merge too, but {}. how i can merge without {} ?!
NERF TIMBITS BLASTER
00:39
MacDannyGun
Рет қаралды 14 МЛН
I Spent 100 Hours Inside The Pyramids!
21:43
MrBeast
Рет қаралды 76 МЛН
jq Scripting Language Tutorial Webinar
1:19:00
perfSONAR Project
Рет қаралды 16 М.
The BEST CLI Tool
9:50
ThePrimeTime
Рет қаралды 216 М.
Command Line Tools ALL Developers Should Know
6:15
ForrestKnight
Рет қаралды 112 М.
Jenkins Pipeline Environment Variables: A Comprehensive Guide
16:44
Szymon Stepniak
Рет қаралды 50 М.
I Spent 100 Hours Inside The Pyramids!
21:43
MrBeast
Рет қаралды 76 МЛН
What if all the world's biggest problems have the same solution?
24:52
jq: A Practical Guide
14:54
Navek
Рет қаралды 17 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
7 Essential Command Line Tools (2022)
9:12
Tech Craft
Рет қаралды 230 М.