jq starts with query
If a user wants to search a json payload using a starts_with or “begins with” or “has prefix” query, jq natively supports it.
How to query using startswith
Given a json array, searching for a specific string that startswith a prefix is easy.
1{
2 "people": [
3 {
4 "firstName": "thomas",
5 "age": 25
6 },
7 {
8 "firstName": "sally",
9 "age": 28
10 }
11 ]
12}Find each person if their name begins with sal.
1jq -r '.people[]|select(.firstName | startswith("sal"))' people.jsonOutput
1{
2 "firstName": "sally",
3 "age": 28
4}