jq Arrays and Objects/Rename keys with entries

Rename object keys during transformation.

Section: Entries and Key-Value Maps

Rename keys with entries

bash
bash
echo '{"first_name":"Alice","last_name":"Ng"}' | jq 'to_entries | map(.key |= gsub("_"; "-")) | from_entries'
Explanation

Great for adapting between naming conventions.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Entries and Key-Value Maps
Filter object entries by value
Remove entries below a threshold.
OpenIn sheetbashsame section
Create object from array items
Index objects by a field.
OpenIn sheetbashsame section
Create grouped object
Group items by key and emit object buckets.
OpenIn sheetbashsame section
Map object values
Transform each value while keeping keys unchanged.
OpenIn sheetbashsame section
First array item
Get the first element.
OpenIn sheetbash1 tag match
Object values
Return all object values as an array.
OpenIn sheetbash1 tag match