From 87a61445b84b403605459df98e9b61038891a0ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BA=A7n=20=C4=90=C3=ACnh=20=C4=90=E1=BB=93ng?= <76928878+vanvuvuong@users.noreply.github.com> Date: Mon, 2 Dec 2024 10:21:01 +0700 Subject: [PATCH] jq: update page (#14841) --- pages/common/jq.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pages/common/jq.md b/pages/common/jq.md index ff73b17dc..faea3efb6 100644 --- a/pages/common/jq.md +++ b/pages/common/jq.md @@ -3,10 +3,6 @@ > A JSON processor that uses a domain-specific language (DSL). > More information: . -- Execute a specific expression (print a colored and formatted JSON output): - -`{{cat path/to/file.json}} | jq '.'` - - Execute a specific expression only using the `jq` binary (print a colored and formatted JSON output): `jq '.' {{/path/to/file.json}}` @@ -19,9 +15,9 @@ `{{cat path/to/file.json}} | jq {{--arg "name1" "value1" --arg "name2" "value2" ...}} '{{. + $ARGS.named}}'` -- Print specific keys: +- Create new JSON object via old JSON objects from multiple files: -`{{cat path/to/file.json}} | jq '{{.key1, .key2, ...}}'` +`{{cat path/to/multiple_json_file_*.json}} | jq '{{{newKey1: .key1, newKey2: .key2.nestedKey, ...}}}'` - Print specific array items: @@ -31,6 +27,10 @@ `{{cat path/to/file.json}} | jq '.[]'` +- Print objects with 2-condition filter in array: + +`{{cat path/to/file.json}} | jq '.[] | select((.key1=="value1") and .key2=="value2")'` + - Add/remove specific keys: `{{cat path/to/file.json}} | jq '. {{+|-}} {{{"key1": "value1", "key2": "value2", ...}}}'`