From 8a3d9efe4b2940b018cd563de0276e920927e2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czechowski?= Date: Sat, 29 Sep 2018 18:05:16 +0200 Subject: [PATCH] Inceased readability I care about readability and had to comit that changes. It was not directly concludable what the output is. Feel free to accept or add your idea of how to highlight the output. --- README.md | 51 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b1110c2..26e3263 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,11 @@ you use, `jmespath.search`: ``` -> var jmespath = require('jmespath'); -> jmespath.search({foo: {bar: {baz: [0, 1, 2, 3, 4]}}}, "foo.bar.baz[2]") -2 +var jmespath = require('jmespath'); + +jmespath.search({foo: {bar: {baz: [0, 1, 2, 3, 4]}}}, "foo.bar.baz[2]") + +// output: 2 ``` In the example we gave the ``search`` function input data of @@ -26,19 +28,36 @@ The JMESPath language can do a lot more than select an element from a list. Here are a few more examples: ``` -> jmespath.search({foo: {bar: {baz: [0, 1, 2, 3, 4]}}}, "foo.bar") -{ baz: [ 0, 1, 2, 3, 4 ] } - -> jmespath.search({"foo": [{"first": "a", "last": "b"}, - {"first": "c", "last": "d"}]}, - "foo[*].first") -[ 'a', 'c' ] - -> jmespath.search({"foo": [{"age": 20}, {"age": 25}, - {"age": 30}, {"age": 35}, - {"age": 40}]}, - "foo[?age > `30`]") -[ { age: 35 }, { age: 40 } ] +jmespath.search({ + foo: { + bar: { + baz: [0, 1, 2, 3, 4] + } + } +}, "foo.bar") + +// output: { baz: [ 0, 1, 2, 3, 4 ] } + +jmespath.search({ + "foo": [ + {"first": "a", "last": "b"}, + {"first": "c", "last": "d"} + ] +}, "foo[*].first") + +// output: [ 'a', 'c' ] + +jmespath.search({ + "foo": [ + {"age": 20}, + {"age": 25}, + {"age": 30}, + {"age": 35}, + {"age": 40} + ] +}, "foo[?age > `30`]") + +// ouput: [ { age: 35 }, { age: 40 } ] ``` ## More Resources