From 89c2015940c27891f6d57f0bd1cf6f4c8f186345 Mon Sep 17 00:00:00 2001 From: maximpertsov Date: Wed, 21 Dec 2016 18:40:12 -0500 Subject: [PATCH] jq: add page (#1092) --- pages/common/jq.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 pages/common/jq.md diff --git a/pages/common/jq.md b/pages/common/jq.md new file mode 100644 index 000000000..a7aa53b99 --- /dev/null +++ b/pages/common/jq.md @@ -0,0 +1,27 @@ +# jq + +> A lightweight and flexible command-line JSON processor. + +- Output JSON file: + +`cat {{file}} | jq` + +- Output all elements from JSON array in file, or all key-value pairs from JSON objects in file: + +`cat {{file}} | jq .[]` + +- Read JSON objects from file, into array, and output (inverse of `jq .[]`): + +`cat {{file}} | jq --slurp` + +- Output first element in JSON file: + +`cat {{file}} | jq .[0]` + +- Output "key" of first element in JSON file: + +`cat {{file}} | jq .[0].{{key}}` + +- Output "key" of each element in JSON file: + +`cat {{file}} | jq 'map(.{{key}})'`