From fc69d1297dee295a9025e4a1220a405d40ee307d Mon Sep 17 00:00:00 2001 From: Matt Watson Date: Fri, 17 Jul 2020 18:37:49 +0100 Subject: [PATCH] jq: Add example for constructing new JSON object (#4172) Co-authored-by: Starbeamrainbowlabs --- pages/common/jq.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pages/common/jq.md b/pages/common/jq.md index 15e73fddb3..42555d7590 100644 --- a/pages/common/jq.md +++ b/pages/common/jq.md @@ -27,6 +27,10 @@ `cat {{file.json}} | jq 'map(.{{key_name}})'` +- Output the value of multiple keys as a new JSON object (assuming the input JSON has the keys `key_name` and `other_key_name`): + +`cat {{file.json}} | jq '{{{my_new_key}}: .{{key_name}}, {{my_other_key}}: {{other_key_name}}}'` + - Combine multiple filters: `cat {{file.json}} | jq 'unique | sort | reverse'`