|
1 | 1 | # jmespath.js
|
2 | 2 |
|
3 |
| -This is a javascript implementation of JMESPath. |
| 3 | +jmespath.js is a javascript implementation of JMESPath, |
| 4 | +which is a query language for JSON. It will take a JSON |
| 5 | +document and transform it into another JSON document |
| 6 | +through a JMESPath expression. |
4 | 7 |
|
5 |
| -See http://jmespath.org for more info. |
| 8 | +Using jmespath.js is really easy. There's a single function |
| 9 | +you use, `jmespath.search`: |
| 10 | + |
| 11 | + |
| 12 | +``` |
| 13 | +> var jmespath = require('jmespath'); |
| 14 | +> jmespath.search({foo: {bar: {baz: [0, 1, 2, 3, 4]}}}, "foo.bar.baz[2]") |
| 15 | +2 |
| 16 | +``` |
| 17 | + |
| 18 | +In the example we gave the ``search`` function input data of |
| 19 | +`{foo: {bar: {baz: [0, 1, 2, 3, 4]}}}` as well as the JMESPath |
| 20 | +expression `foo.bar.baz[2]`, and the `search` function evaluated |
| 21 | +the expression against the input data to produce the result ``2``. |
| 22 | + |
| 23 | +The JMESPath language can do a lot more than select an element |
| 24 | +from a list. Here are a few more examples: |
| 25 | + |
| 26 | +``` |
| 27 | +> jmespath.search({foo: {bar: {baz: [0, 1, 2, 3, 4]}}}, "foo.bar") |
| 28 | +{ baz: [ 0, 1, 2, 3, 4 ] } |
| 29 | +
|
| 30 | +> jmespath.search({"foo": [{"first": "a", "last": "b"}, |
| 31 | + {"first": "c", "last": "d"}]}, |
| 32 | + "foo[*].first") |
| 33 | +[ 'a', 'c' ] |
| 34 | +
|
| 35 | +> jmespath.search({"foo": [{"age": 20}, {"age": 25}, |
| 36 | + {"age": 30}, {"age": 35}, |
| 37 | + {"age": 40}]}, |
| 38 | + "foo[?age > `30`]") |
| 39 | +[ { age: 35 }, { age: 40 } ] |
| 40 | +``` |
| 41 | + |
| 42 | +## More Resources |
| 43 | + |
| 44 | +The example above only show a small amount of what |
| 45 | +a JMESPath expression can do. If you want to take a |
| 46 | +tour of the language, the *best* place to go is the |
| 47 | +[JMESPath Tutorial](http://jmespath.org/tutorial.html). |
| 48 | + |
| 49 | +One of the best things about JMESPath is that it is |
| 50 | +implemented in many different programming languages including |
| 51 | +python, ruby, php, lua, etc. To see a complete list of libraries, |
| 52 | +check out: http://jmespath.org/libraries.html. |
| 53 | + |
| 54 | +And finally, the full JMESPath specification can be found |
| 55 | +on the [JMESPath site](http://jmespath.org/specification.html). |
0 commit comments