What Will You Learn?
- What is jq?
- What are the use cases for jq?
- How do I parse a remote JSON file with jq?
- How do I parse a local JSON file with jq?
- How do I reformat a local JSON file with jq?
The Basics
The jq command-line JSON parser is a welcome tool in any programmer’s toolbelt. Use jq to parse JSON to simplify collecting essential information from JSON files.
Primary Use Cases
- Parse JSON
- Query JSON
- Reformat parsed JSON
Less Suitable Use Cases
- Parsing raw text and XML
Parse A Remote File
Install curl and install jq.
Run this command to query a specific office name from offices.json.
curl --silent https://raw.githubusercontent.com/jeffabailey/learn/main/tools/jq/offices.json | jq .[].name | tr -d '"'
Press the green run button to see the output of this command.
Parse A Local File
Download offices.json and run this command in your download folder.
cat ./offices.json | jq .[].name
Press the green run button to see the output of this command.
Reformat A Local File
I am using the previously downloaded offices.json to run this command.
cat ./offices.json | jq '.[] | {name,location} | join(" is in ")'
Press the green run button to see the output of this command.
The join() function allows for quick formatting.
Try this command for ad-hoc string concatenation.
cat ./offices.json | jq '.[] | .name + " is in " + .location'
Learn jq - Beyond the Basics
Related Content
- jq Cheat Sheet
- JSONPath Online Evaluator
- How to Clean JSON Data at the Command Line
- Guide to Linux jq Command for JSON Processing - Baeldung
- Online Generate Test Data - Generate some JSON files to play with.
- tput documentation - Generates color in bash shells.
- Add Color to Shell Scripts - Take tput further for your use cases.
Other Learning
- How Do I Learn Effectively?
- Learn 3D Graphics
- Learn Amazon Athena
- Learn Asymptotic Notations
- Learn AWS Amplify
- Learn Color Theory
- Learn Data Visualization
- Learn Design Systems
- Learn ECS
- Learn GitHub
- Learn How To Prioritize
- Learn Java
- Learn Java Coding Challenges
- Learn JavaScript
- Learn jq
- Learn Kubernetes
- Learn Python
- Learn Rendanheyi
- Learn SignalFx
- Learn Software Architecture
- Learn Software Design Patterns
- Learn Structurizr
- Learn systemd
- Learn Terraform