Store a subexpression and reuse it later.
Section: Variables, Reduce, and Advanced Transformations
Capture value into variable
bash
bash
echo '{"user":{"name":"alice"},"team":"eng"}' | jq '.user as $u | {name: $u.name, team: .team}'Explanation
The `as $var` syntax avoids repeating long paths.
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 Variables, Reduce, and Advanced Transformations
Convert object to entries array
Represent an object as key-value entry objects.
Convert entries back to object
Turn key-value entry objects into a normal object.
Recursively transform all strings
Walk the document and mutate matching values.