Browse code

vendor: jmespath/go-jmespath v0.3.0

This update is just adding some typo-fixes and adding a go.mod, but
pins it to a tagged release;

https://github.com/jmespath/go-jmespath/compare/c2b33e8439af944379acbdd9c3a5fe0bc44bd8a5...v0.3.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2020/04/04 07:59:15
Showing 5 changed files
... ...
@@ -106,7 +106,7 @@ github.com/fsnotify/fsnotify                        45d7d09e39ef4ac08d493309fa03
106 106
 
107 107
 # awslogs deps
108 108
 github.com/aws/aws-sdk-go                           2590bc875c54c9fda225d8e4e56a9d28d90c6a47 # v1.28.11
109
-github.com/jmespath/go-jmespath                     c2b33e8439af944379acbdd9c3a5fe0bc44bd8a5 # see https://github.com/aws/aws-sdk-go/blob/2590bc875c54c9fda225d8e4e56a9d28d90c6a47/Gopkg.toml#L42
109
+github.com/jmespath/go-jmespath                     2d053f87d1d7f9f48196ae04cf3daea4273d207d # v0.3.0
110 110
 
111 111
 # logentries
112 112
 github.com/bsphere/le_go                            7a984a84b5492ae539b79b62fb4a10afc63c7bcf
... ...
@@ -4,4 +4,84 @@
4 4
 
5 5
 
6 6
 
7
-See http://jmespath.org for more info.
7
+go-jmespath is a GO implementation of JMESPath,
8
+which is a query language for JSON.  It will take a JSON
9
+document and transform it into another JSON document
10
+through a JMESPath expression.
11
+
12
+Using go-jmespath is really easy.  There's a single function
13
+you use, `jmespath.search`:
14
+
15
+
16
+```go
17
+> import "github.com/jmespath/go-jmespath"
18
+>
19
+> var jsondata = []byte(`{"foo": {"bar": {"baz": [0, 1, 2, 3, 4]}}}`) // your data
20
+> var data interface{}
21
+> err := json.Unmarshal(jsondata, &data)
22
+> result, err := jmespath.Search("foo.bar.baz[2]", data)
23
+result = 2
24
+```
25
+
26
+In the example we gave the ``search`` function input data of
27
+`{"foo": {"bar": {"baz": [0, 1, 2, 3, 4]}}}` as well as the JMESPath
28
+expression `foo.bar.baz[2]`, and the `search` function evaluated
29
+the expression against the input data to produce the result ``2``.
30
+
31
+The JMESPath language can do a lot more than select an element
32
+from a list.  Here are a few more examples:
33
+
34
+```go
35
+> var jsondata = []byte(`{"foo": {"bar": {"baz": [0, 1, 2, 3, 4]}}}`) // your data
36
+> var data interface{}
37
+> err := json.Unmarshal(jsondata, &data)
38
+> result, err := jmespath.search("foo.bar", data)
39
+result = { "baz": [ 0, 1, 2, 3, 4 ] }
40
+
41
+
42
+> var jsondata  = []byte(`{"foo": [{"first": "a", "last": "b"},
43
+                           {"first": "c", "last": "d"}]}`) // your data
44
+> var data interface{}
45
+> err := json.Unmarshal(jsondata, &data)
46
+> result, err := jmespath.search({"foo[*].first", data)
47
+result [ 'a', 'c' ]
48
+
49
+
50
+> var jsondata = []byte(`{"foo": [{"age": 20}, {"age": 25},
51
+                           {"age": 30}, {"age": 35},
52
+                           {"age": 40}]}`) // your data
53
+> var data interface{}
54
+> err := json.Unmarshal(jsondata, &data)
55
+> result, err := jmespath.search("foo[?age > `30`]")
56
+result = [ { age: 35 }, { age: 40 } ]
57
+```
58
+
59
+You can also pre-compile your query. This is usefull if 
60
+you are going to run multiple searches with it:
61
+
62
+```go
63
+	> var jsondata = []byte(`{"foo": "bar"}`)
64
+	> var data interface{}
65
+    > err := json.Unmarshal(jsondata, &data)
66
+	> precompiled, err := Compile("foo")
67
+	> if err != nil{
68
+    >   // ... handle the error
69
+    > }
70
+    > result, err := precompiled.Search(data)
71
+	result = "bar"
72
+```
73
+
74
+## More Resources
75
+
76
+The example above only show a small amount of what
77
+a JMESPath expression can do.  If you want to take a
78
+tour of the language, the *best* place to go is the
79
+[JMESPath Tutorial](http://jmespath.org/tutorial.html).
80
+
81
+One of the best things about JMESPath is that it is
82
+implemented in many different programming languages including
83
+python, ruby, php, lua, etc.  To see a complete list of libraries,
84
+check out the [JMESPath libraries page](http://jmespath.org/libraries.html).
85
+
86
+And finally, the full JMESPath specification can be found
87
+on the [JMESPath site](http://jmespath.org/specification.html).
... ...
@@ -2,7 +2,7 @@ package jmespath
2 2
 
3 3
 import "strconv"
4 4
 
5
-// JMESPath is the epresentation of a compiled JMES path query. A JMESPath is
5
+// JMESPath is the representation of a compiled JMES path query. A JMESPath is
6 6
 // safe for concurrent use by multiple goroutines.
7 7
 type JMESPath struct {
8 8
 	ast  ASTNode
9 9
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+module github.com/jmespath/go-jmespath
1
+
2
+go 1.14
3
+
4
+require github.com/stretchr/testify v1.5.1
... ...
@@ -137,7 +137,7 @@ func (p *Parser) Parse(expression string) (ASTNode, error) {
137 137
 	}
138 138
 	if p.current() != tEOF {
139 139
 		return ASTNode{}, p.syntaxError(fmt.Sprintf(
140
-			"Unexpected token at the end of the expresssion: %s", p.current()))
140
+			"Unexpected token at the end of the expression: %s", p.current()))
141 141
 	}
142 142
 	return parsed, nil
143 143
 }