@@ -6,12 +6,49 @@ https://github.com/kennknowles/python-jsonpath-rw
6
6
[ ![ Build Status] ( https://travis-ci.org/kennknowles/python-jsonpath-rw.png )] ( https://travis-ci.org/kennknowles/python-jsonpath-rw )
7
7
8
8
This library provides a robust and significantly extended implementation of JSONPath for Python.
9
+ It is tested with Python 2.6, 2.7, 3.2, and 3.3.
9
10
10
11
This library differs from other JSONPath implementations in that it
11
12
is a full _ language_ implementation, meaning the JSONPath expressions
12
13
are first class objects, easy to analyze, transform, parse, print,
13
14
and extend. (You can also execute them :-)
14
15
16
+ Quick Start
17
+ -----------
18
+
19
+ To install, use pip:
20
+
21
+ ```
22
+ $ pip install jsonpath-rw
23
+ ```
24
+
25
+ Then:
26
+
27
+ ``` python
28
+ $ python
29
+
30
+ >> > from jsonpath_rw import jsonpath, parse
31
+
32
+ # A robust parser, not just a regex, makes powerful extensions possible
33
+ >> > jsonpath_expr = parse(' foo[*].baz' )
34
+
35
+ # Extracting values is easy
36
+ >> > [match.value for match in jsonpath_expr.find({' foo' : [{' baz' : 1 }, {' baz' : 2 }]})]
37
+ [1 , 2 ]
38
+
39
+ # Matches remember where they came from
40
+ >> > [str (match.full_path) for match in jsonpath_expr.find({' foo' : [{' baz' : 1 }, {' baz' : 2 }]})]
41
+ [' foo.[0].baz' , ' foo.[1].baz' ]
42
+
43
+ # And this can be useful for automatically providing ids for bits of data that do not have them (currently a global switch)
44
+ >> > jsonpath.auto_id_field = ' id'
45
+ >> > [match.value for match in parse(' foo[*].id' ).find({' foo' : [{' id' : ' bizzle' }, {' baz' : 3 }]})]
46
+ [' foo.bizzle' , ' foo.[1]' ]
47
+
48
+ # You can also build expressions directly quite easily
49
+ >> > jsonpath_expr_direct = Fields(' foo' ).child(Slice(' *' )).child(Fields(' baz' )) # This is equivalent
50
+ ```
51
+
15
52
16
53
JSONPath Syntax
17
54
---------------
0 commit comments