Uppercase and Lowercase Strings and Array Fields with jq
Use ascii_upcase to uppercase a string or ascii_downcase to lowercase it. For fields inside an array of objects, use map with |= so the rest of each object and the surrounding JSON stay intact.
Uppercase or lowercase one string
With the JSON input "Api École", run either filter:
ascii_upcase
Output:
"API ÉCOLE"
Run uppercase in the jq playground
ascii_downcase
Output:
"api École"
Run lowercase in the jq playground
Only ASCII letters change: É stays uppercase in both outputs. These functions do not perform Unicode or locale-aware case conversion, so do not use them when accented letters must be lowercased correctly.
Change fields inside an array without losing other data
Input:
{
"users": [
{"name": "Ada", "role": "Admin", "active": true},
{"name": "MARC", "role": "Reader", "active": false}
]
}
Lowercase each name and uppercase each role:
.users |= map(.name |= ascii_downcase | .role |= ascii_upcase)
Output:
{
"users": [
{"name": "ada", "role": "ADMIN", "active": true},
{"name": "marc", "role": "READER", "active": false}
]
}
Run the array-field conversion in the jq playground
The outer |= updates only users; map returns every user object, and the inner |= updates only name and role. The active fields are unchanged. This assumes both fields contain strings: a missing field produces a null value and jq reports an error rather than silently skipping it. Check your input types before applying a case filter to mixed data.
These are jq's ASCII case functions, verified with jq 1.8.1 and the browser jq playground. For a different task, see capitalize only the first letter, update fields without losing other values, or the jq cheatsheet. Reference: jq manual, string functions.