SlideShare a Scribd company logo
Introduction to jq
Presented By: Etash Singh
Software Consultant
Knoldus Inc.
About Knoldus
Knoldus is a technology consulting firm with focus on modernizing the digital systems
at the pace your business demands.
DevOps
Functional. Reactive. Cloud Native
01 What is jq?
02 Basic Filters
03 Operators and Functions
04 Conditional and Comparisons
05 Functions
Our Agenda
06 Regular Expressions and Streams
c
What is
jq?
jq is a lightweight and
flexible command-line JSON
processor.
1. jq is like sed for JSON. We can
use it to play with JSON with the
same ease that sed, awk, grep let
us play with text.
2. jq is written in portable C and
has zero runtime dependencies.
Basic Filters
1. Identity (.): The simplest filter. Takes an input and gives an unchanged output. Can
be useful for pretty-printing JSON output from, say, curl.
2. Object Identifier-Index (.foo): We can call it the simplest useful function. It
produces value at index foo or null if there is none.
3. Array Index.[2]: Filter gives output using the given array index. Arrays are zero
based, so .[2] will return the third element. Negative indexing is also possible.
Array/string slice filter is also similar to this.
4. Comma(,): If two filters are separated by comma, the same input will be fed to
both the filters and their outputs will be concatenated in the order the filters were
mentioned.
5. Pipe (|): The | operator combines two filters by feeding the output(s) of the one on
the left into the input of the one on the right. It’s pretty much the same as the Unix
shell’s pipe.
Built In Operators and and functions
1. Addition (+): The operator + takes two filters, applies them both to the same input,
and adds the results together.
2. Subtraction (-): As well as normal arithmetic subtraction on numbers, the -
operator can be used on arrays to remove all occurrences of the second array’s
elements from the first array.
3. length: It returns the length of a string, array, object or null.
4. keys: When provided with an object, the key function returns the keys in it.
5. has(key): Returns true if an object has the specified key, otherwise returns false.
6. map(x): For any filter x, map(x) will run that filter for each element of the input
array, and return the outputs in a new array.
7. del(): Removes key and its corresponding value from an object
8. select(): The select function produces an output if the condition provided is true
otherwise no output at all.
9. sort: This function sorts the input which must be an array.
Conditionals and Comparisons
1. ==, !=
2. if-else-then
3. >,<,>=,<=
4. Alternative Operator(//): A filter of form a//b produces ‘a’ if ‘a’ returns anything
other than false or null. Otherwise it returns ‘b’
Functions
Functions in jq can be defined using the ‘def’ keyword and then used as we use filters
in jq.
Example: def increment: .+1; map(increment)
Input: [1,2,3,4]
Output: [2,3,4,5]
Regular Expressions
The Oniguruma regular expression library is used in Jq.
The Jq regular expression can be used with the following syntax:
● STRING | FILTER( REGEX )
● STRING | FILTER( REGEX; FLAGS )
● STRING | FILTER( [REGEX] )
● STRING | FILTER( [REGEX, FLAGS] )
Here, STRING, REGEX, and FLAGS are jq strings and subject to interpolation.
FILTER is one of the test, match and capture filters.
Regular Expressions
Flags is one of the following which are defined below:
● g - Global search for finding all matches and not just one
● i - Case insensitive search
● m - Multi-line mode
● n - Ignore empty matches
● p - Both s and m modes are enabled
● s - Single line mode
● l - Find longest possible match
● x - Extended regex format (ignore whitespace and formats.
Streaming
The --stream flag is used to parse the input text as a stream, allowing jq programs to
start processing large JSON texts immediately rather than after the parse completes.
There are 3 built-in functions to handle out streaming input:
1. truncate_stream(stream_expression)
2. from_stream(stream_expression)
3. to_stream(stream_expression)
DEMO
OUR CHARTInsert Your Subtitle Here
Reference
https://stedolan.github.io/jq/manual/#ConditionalsandComparisons
Thank You!

More Related Content

PDF
jq: JSON - Like a Boss
ODP
Introduction to jQuery
PDF
Java Collections API
PDF
Lambdas and Streams Master Class Part 2
PDF
The Future of Java: Records, Sealed Classes and Pattern Matching
PDF
Understanding react hooks
PPTX
Advanced Javascript
PDF
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...
jq: JSON - Like a Boss
Introduction to jQuery
Java Collections API
Lambdas and Streams Master Class Part 2
The Future of Java: Records, Sealed Classes and Pattern Matching
Understanding react hooks
Advanced Javascript
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Begin...

What's hot (20)

PDF
Managing users & tables using Oracle Enterprise Manage
PDF
Tweaking the interactive grid
PDF
TestNG - The Next Generation of Unit Testing
PDF
What are Regular Expressions in Java | Java Regex Tutorial Edureka
PPT
PPTX
jQuery
PDF
Android Basic Components
PDF
Design Patterns Illustrated
PPTX
How Hashmap works internally in java
PDF
Sparklens: Understanding the Scalability Limits of Spark Applications with R...
PDF
Angular - Chapter 7 - HTTP Services
PDF
Apuntes de XSD
PPT
JDBC
PPTX
Core java
PPTX
Dependency injection ppt
PPTX
Java- Nested Classes
PPTX
Mongoose and MongoDB 101
PPTX
TestNG Framework
PPTX
Inheritance and Polymorphism in java simple and clear
Managing users & tables using Oracle Enterprise Manage
Tweaking the interactive grid
TestNG - The Next Generation of Unit Testing
What are Regular Expressions in Java | Java Regex Tutorial Edureka
jQuery
Android Basic Components
Design Patterns Illustrated
How Hashmap works internally in java
Sparklens: Understanding the Scalability Limits of Spark Applications with R...
Angular - Chapter 7 - HTTP Services
Apuntes de XSD
JDBC
Core java
Dependency injection ppt
Java- Nested Classes
Mongoose and MongoDB 101
TestNG Framework
Inheritance and Polymorphism in java simple and clear
Ad

Similar to Introduction to JQ (20)

PDF
Exploring JSON With jq
PPT
regular-expressions lecture 28-string regular expression
DOCX
2232021 cs 265 — assignment – json dirhttpswww.cs.dre
PDF
Advanced JavaScript Development
PDF
JSLT: JSON querying and transformation
PDF
Json the-x-in-ajax1588
PDF
PPTX
Stop the noise! - Introduction to the JSON:API specification in Drupal
PDF
History of jQuery
PPTX
NLP_KASHK:Regular Expressions
PDF
Puppet future parser
PPTX
SHELL PROGRAMMING.pptx
PDF
Charlie Talk - JQL In A Nutshell
PDF
Regular Expressions: JavaScript And Beyond
KEY
groovy & grails - lecture 3
PDF
Data science at the command line
PDF
VISUAL CHEAT SHEET
PDF
J query 1.5-visual-cheat-sheet
PDF
Computational Social Science, Lecture 09: Data Wrangling
PDF
Why Zsh is Cooler than Your Shell
Exploring JSON With jq
regular-expressions lecture 28-string regular expression
2232021 cs 265 — assignment – json dirhttpswww.cs.dre
Advanced JavaScript Development
JSLT: JSON querying and transformation
Json the-x-in-ajax1588
Stop the noise! - Introduction to the JSON:API specification in Drupal
History of jQuery
NLP_KASHK:Regular Expressions
Puppet future parser
SHELL PROGRAMMING.pptx
Charlie Talk - JQL In A Nutshell
Regular Expressions: JavaScript And Beyond
groovy & grails - lecture 3
Data science at the command line
VISUAL CHEAT SHEET
J query 1.5-visual-cheat-sheet
Computational Social Science, Lecture 09: Data Wrangling
Why Zsh is Cooler than Your Shell
Ad

More from Knoldus Inc. (20)

PPTX
Angular Hydration Presentation (FrontEnd)
PPTX
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
PPTX
Self-Healing Test Automation Framework - Healenium
PPTX
Kanban Metrics Presentation (Project Management)
PPTX
Java 17 features and implementation.pptx
PPTX
Chaos Mesh Introducing Chaos in Kubernetes
PPTX
GraalVM - A Step Ahead of JVM Presentation
PPTX
Nomad by HashiCorp Presentation (DevOps)
PPTX
Nomad by HashiCorp Presentation (DevOps)
PPTX
DAPR - Distributed Application Runtime Presentation
PPTX
Introduction to Azure Virtual WAN Presentation
PPTX
Introduction to Argo Rollouts Presentation
PPTX
Intro to Azure Container App Presentation
PPTX
Insights Unveiled Test Reporting and Observability Excellence
PPTX
Introduction to Splunk Presentation (DevOps)
PPTX
Code Camp - Data Profiling and Quality Analysis Framework
PPTX
AWS: Messaging Services in AWS Presentation
PPTX
Amazon Cognito: A Primer on Authentication and Authorization
PPTX
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
PPTX
Managing State & HTTP Requests In Ionic.
Angular Hydration Presentation (FrontEnd)
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Self-Healing Test Automation Framework - Healenium
Kanban Metrics Presentation (Project Management)
Java 17 features and implementation.pptx
Chaos Mesh Introducing Chaos in Kubernetes
GraalVM - A Step Ahead of JVM Presentation
Nomad by HashiCorp Presentation (DevOps)
Nomad by HashiCorp Presentation (DevOps)
DAPR - Distributed Application Runtime Presentation
Introduction to Azure Virtual WAN Presentation
Introduction to Argo Rollouts Presentation
Intro to Azure Container App Presentation
Insights Unveiled Test Reporting and Observability Excellence
Introduction to Splunk Presentation (DevOps)
Code Camp - Data Profiling and Quality Analysis Framework
AWS: Messaging Services in AWS Presentation
Amazon Cognito: A Primer on Authentication and Authorization
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Managing State & HTTP Requests In Ionic.

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Mushroom cultivation and it's methods.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Tartificialntelligence_presentation.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
August Patch Tuesday
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
A Presentation on Artificial Intelligence
PPTX
Programs and apps: productivity, graphics, security and other tools
Network Security Unit 5.pdf for BCA BBA.
Mushroom cultivation and it's methods.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
1. Introduction to Computer Programming.pptx
Tartificialntelligence_presentation.pptx
Spectroscopy.pptx food analysis technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Heart disease approach using modified random forest and particle swarm optimi...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25-Week II
August Patch Tuesday
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
cloud_computing_Infrastucture_as_cloud_p
OMC Textile Division Presentation 2021.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
A Presentation on Artificial Intelligence
Programs and apps: productivity, graphics, security and other tools

Introduction to JQ

  • 1. Introduction to jq Presented By: Etash Singh Software Consultant Knoldus Inc.
  • 2. About Knoldus Knoldus is a technology consulting firm with focus on modernizing the digital systems at the pace your business demands. DevOps Functional. Reactive. Cloud Native
  • 3. 01 What is jq? 02 Basic Filters 03 Operators and Functions 04 Conditional and Comparisons 05 Functions Our Agenda 06 Regular Expressions and Streams
  • 4. c What is jq? jq is a lightweight and flexible command-line JSON processor. 1. jq is like sed for JSON. We can use it to play with JSON with the same ease that sed, awk, grep let us play with text. 2. jq is written in portable C and has zero runtime dependencies.
  • 5. Basic Filters 1. Identity (.): The simplest filter. Takes an input and gives an unchanged output. Can be useful for pretty-printing JSON output from, say, curl. 2. Object Identifier-Index (.foo): We can call it the simplest useful function. It produces value at index foo or null if there is none. 3. Array Index.[2]: Filter gives output using the given array index. Arrays are zero based, so .[2] will return the third element. Negative indexing is also possible. Array/string slice filter is also similar to this. 4. Comma(,): If two filters are separated by comma, the same input will be fed to both the filters and their outputs will be concatenated in the order the filters were mentioned. 5. Pipe (|): The | operator combines two filters by feeding the output(s) of the one on the left into the input of the one on the right. It’s pretty much the same as the Unix shell’s pipe.
  • 6. Built In Operators and and functions 1. Addition (+): The operator + takes two filters, applies them both to the same input, and adds the results together. 2. Subtraction (-): As well as normal arithmetic subtraction on numbers, the - operator can be used on arrays to remove all occurrences of the second array’s elements from the first array. 3. length: It returns the length of a string, array, object or null. 4. keys: When provided with an object, the key function returns the keys in it. 5. has(key): Returns true if an object has the specified key, otherwise returns false. 6. map(x): For any filter x, map(x) will run that filter for each element of the input array, and return the outputs in a new array. 7. del(): Removes key and its corresponding value from an object 8. select(): The select function produces an output if the condition provided is true otherwise no output at all. 9. sort: This function sorts the input which must be an array.
  • 7. Conditionals and Comparisons 1. ==, != 2. if-else-then 3. >,<,>=,<= 4. Alternative Operator(//): A filter of form a//b produces ‘a’ if ‘a’ returns anything other than false or null. Otherwise it returns ‘b’
  • 8. Functions Functions in jq can be defined using the ‘def’ keyword and then used as we use filters in jq. Example: def increment: .+1; map(increment) Input: [1,2,3,4] Output: [2,3,4,5]
  • 9. Regular Expressions The Oniguruma regular expression library is used in Jq. The Jq regular expression can be used with the following syntax: ● STRING | FILTER( REGEX ) ● STRING | FILTER( REGEX; FLAGS ) ● STRING | FILTER( [REGEX] ) ● STRING | FILTER( [REGEX, FLAGS] ) Here, STRING, REGEX, and FLAGS are jq strings and subject to interpolation. FILTER is one of the test, match and capture filters.
  • 10. Regular Expressions Flags is one of the following which are defined below: ● g - Global search for finding all matches and not just one ● i - Case insensitive search ● m - Multi-line mode ● n - Ignore empty matches ● p - Both s and m modes are enabled ● s - Single line mode ● l - Find longest possible match ● x - Extended regex format (ignore whitespace and formats.
  • 11. Streaming The --stream flag is used to parse the input text as a stream, allowing jq programs to start processing large JSON texts immediately rather than after the parse completes. There are 3 built-in functions to handle out streaming input: 1. truncate_stream(stream_expression) 2. from_stream(stream_expression) 3. to_stream(stream_expression)
  • 12. DEMO
  • 13. OUR CHARTInsert Your Subtitle Here Reference https://stedolan.github.io/jq/manual/#ConditionalsandComparisons