 So excited to be here to talk to you guys about JQ. JQ, my hand moved, sorry. So JQ is a practical and purely functional language that is used oftentimes to inspect JSON and look at JSON, so that's an important part of it. But first I want to talk about what purely functional means. So if in a purely functional language, when you have a function, it just returns something. That's something. That's all it does. So in a different language, you might do some things, a function you have several lines, and then at the end you return something in a pure language, you just return something. Which means that you don't have things like network calls, you don't have printing to a console, you don't have mutation in other parts of the program, it's just a definition of something. Okay. And JSON, here's an example of some JSON. We have a file called colors.json, and we've catted it, which prints the output. What I want you to see here is that this is so ugly in that I have no idea, I can't read this, it's horrible. Yeah, so here we have some pretty printed JSON colors, right? And when we get this by piping to jq. This is our first jq program and it's just the identity function. It says whatever the input is, just print the output. So jq. We can also use jq to inspect parts of that JSON. So here we're saying, I think dot is a list and I want to get the first element from it. So that's what's happening here, right? So we go from jq. to get the first element and it prints the first element. When we can also look at different parts of that element. So here we're saying I want to get the first element's color, yeah. And this is why jq was made. This is what it's used for most often, looking at and thinking about JSON. But jq is also a programming language. And that's why I'm here. So first I'm going to talk to you about why jq is a programming language and then I'm going to talk to you about why jq is an awesome programming language. Bang, bang. So jq has numbers. jq has strings, objects, which are mappings from keys to any kind of value, lists, which is a set of things, right? And no. And what you can see here is that these data types are just JSON. These are exactly what we have in JSON. So whenever you're working on some data in jq, you get exactly whatever you want in JSON. And you can think of JSON as a jq construction if you want to. Now, here is a jq expression. And when I have this arrow, I mean it evaluates to something. So color red evaluates to color red. And when I have a pipe, this is how I apply functions in jq. So I have a pipe, and I'm piping from color red into the function dot color. And I get the key red, the value red. When I try to get the color of an object that has no keys, I get null. And if I try to pipe one object into another object, I just get the second object. Because it's purely functional, you can think of an object as just a constant function that doesn't look at its input. It's its data type. You can also make a new object here that has a different color, which is pink. And the cool thing about this is that it's not mutating anything. It's just a construction of a new object with the color pink. Cool. If then else. jq has if then else. In previous versions of this talk, I've said, like, this is the dumbest slide. I don't like this one. I'm not going to judge language constructs here. It's branching additionals. They exist. We have an object count to go to 1. And we're saying, if the count is 0, print the string 0. Otherwise 1. Otherwise many. Sorry, otherwise if the count is 1, many. And this just prints 1. So it works. Yeah. jq also has functions, which we've seen one of. We've seen the dot color function. And you can think of any expression as jq as a function that has input and output. Even the jq function as a whole has input as a series of lines and output as a series of lines with the program run against each of them. And a function can have parameters. So you can pass parts of the function into parts of different, like, expressions into the function. So here is a function that has no parameters, length. Thank you, Vancouver organizers. I'm so happy to be here. It's awesome. And the length of that is 25. Maybe a little bit more. We have an object here. We can get the keys of that, which gives us a list of q and a. Now, here are two functions that have parameters. So we have map and select. And we're saying, we're going to take this list. And I want to make a new list with only the elements that are evenly visible, like, two. So only even elements. And you can see it works. And we also have, so, yeah, that's that. We'll get more. OK, so here we have a function called. This is the function definition of select, which we just saw. And it says, OK, if the function passed in evaluates to a truthy value, which is anything other than false and nil, then we're going to keep that thing that it's applied to. Otherwise, we're going to not keep it. We're going to have an empty return value. And that's it. So here we have a list, where we're mapping the select across. And then we get 246. Now, I've made a buggy select for you. It took a lot of coding. But here we have a buggy select. And you can see the only difference is that we have two pipes to the function instead of the implicit input parameter of just the identity. Now, when we pipe two to the function, you'll see that it always is divisible by two. And that dot modulo 2 equals 0 is always true. So we get that is for the same for all of the elements. The interesting part about this is that the dot here is relative to where f is placed within the function definition, not relative to where the function is called. So this is how we can make generic programming and stuff like that. And it's pretty fun. But JQ also has variables. So we're at bang, bang, gone. We can split it up. Get the third piece. Say that it's called location. And then make a new object with that location. And it works. It's truthful, too. And yeah, we have variables. They can be also considered bindings. Since you can't change the variable, they don't change. But they're called variables in the manual. So I want you to know that term. OK, here's a file. Apparently, files are in brackets. And it's called winter.jq. And it has a function wonderland, which is splitting on commas and spaces. And here's another file, main.jq, where we import winter and we make a function main. Snow, snow, snow. We pass it to winter wonderland. And the output is snow, comma, snow, comma, snow. A list, right? And we're importing a new file. We're calling a function. And this is the building blocks of a large jq project, right? jq doesn't just have to be in one line. It can be huge, massively constructed files. So that is something that I want you to know. But I think you understand that jq is a programming language now. I don't have to keep rousing that point. But before I got into why it's such an awesome programming language, I do have a confession in that I lied to everyone. I am sorry a little bit. And jq is not pure. And it's mostly pure, but it's not pure in that there's this little function called debug, which is the same thing functionally as the identity. It's the same thing as dot. So we're just going to take the input and return the output. But it prints to standard error what passed in the input. And it prints JSON. So you can operate on that if you want to. So here we're passing so cool to debug. And we get standard error of so cool. Here we're saying we're going to split so cool. And then we're going to pass. So we print it to debug. And we get a list of all of the characters of so cool. It's pretty cool, right? So yeah, what's interesting about this is that we can go through each part of our program. And since it's a functional language, it's just one big construction, one big definition of an object. And we can see at each part of our program what is exactly happening, what's being constructed. And so we have a range of numbers, which then get transposed next to the characters. And then we map them into character and position objects. And this makes programming in JQ really, really fun, because you can interactively inspect your program as JSON, pass different parts of JSON to it. It's really cool. And it's also interesting that being purely functional helps here, because otherwise you wouldn't have a construction that you can do this with. And other purely functional languages like Haskell or Idris, you have to have a whole other type to monad, do some line of printing. And it's really complicated and scares me. So I much prefer just having a debug function that is not pure and just spews out exactly what I want to see. So thank you so much. I would love to talk more about this or programming languages in the future. And the manual is phenomenal. So if you want to learn more about JQ, definitely go there.