Object construction { ... } builds a brand-new object from the input — the way you pick, rename,
and reshape fields.
Example input
{ "id": 7, "first": "Ada", "last": "Lovelace", "age": 36 }
Pick and rename fields
jq '{ name: .first, surname: .last }' data.json
Output:
{ "name": "Ada", "surname": "Lovelace" }
Shorthand: keep a field under its own name
{id} is shorthand for { id: .id }:
jq '{ id, first }' data.json # { "id": 7, "first": "Ada" }
Computed values
jq '{ fullName: (.first + " " + .last), adult: (.age >= 18) }' data.json
Reshape every item in an array
jq 'map({ id, name: .first })' people.json
Dynamic (computed) keys
Wrap a key expression in parentheses:
jq '{ (.first): .age }' data.json # { "Ada": 36 }
Build an object from key/value pairs
echo '[["a",1],["b",2]]' | jq 'map({key: .[0], value: .[1]}) | from_entries'
# { "a": 1, "b": 2 }
Wrap computed values in parentheses: { total: (.a + .b) } — without them, jq parses the +
as part of the object syntax and errors. Keys that aren’t simple identifiers also need parens or
quotes: { "full name": .x } or { (.k): .v }.