1+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
2+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3+
4+ - [ jsonpath-python] ( #jsonpath-python )
5+ - [ Features] ( #features )
6+ - [ Examples] ( #examples )
7+ - [ Fields-Extractor] ( #fields-extractor )
8+ - [ Multi-selection and inverse-selection filtering] ( #multi-selection-and-inverse-selection-filtering )
9+ - [ Sorting by multiple fields, ascending and descending order] ( #sorting-by-multiple-fields-ascending-and-descending-order )
10+
11+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
12+
113# jsonpath-python
214
315A more powerful JSONPath implementations in modern python.
@@ -6,4 +18,134 @@ A more powerful JSONPath implementations in modern python.
618
719- [x] Light. (No need to install third-party dependencies.)
820- [ ] Support fields-extractor.
9- - [ ] Support simple multi-selection and inverse-selection.
21+ - [ ] Support multi-selection and inverse-selection filtering.
22+ - [ ] Support sorting by multiple fields, ascending and descending order.
23+
24+ ## Examples
25+
26+ JSON format data:
27+
28+ ``` python
29+ data = {
30+ " store" : {
31+ " book" : [
32+ {
33+ " category" : " reference" ,
34+ " author" : " Nigel Rees" ,
35+ " title" : " Sayings of the Century" ,
36+ " price" : 8.95
37+ },
38+ {
39+ " category" : " fiction" ,
40+ " author" : " Evelyn Waugh" ,
41+ " title" : " Sword of Honour" ,
42+ " price" : 12.99
43+ },
44+ {
45+ " category" : " fiction" ,
46+ " author" : " Herman Melville" ,
47+ " title" : " Moby Dick" ,
48+ " isbn" : " 0-553-21311-3" ,
49+ " price" : 8.99
50+ },
51+ {
52+ " category" : " fiction" ,
53+ " author" : " J. R. R. Tolkien" ,
54+ " title" : " The Lord of the Rings" ,
55+ " isbn" : " 0-395-19395-8" ,
56+ " price" : 22.99
57+ }
58+ ],
59+ " bicycle" : {
60+ " color" : " red" ,
61+ " price" : 19.95
62+ }
63+ }
64+ }
65+ ```
66+
67+ ### Fields-Extractor
68+
69+ ``` python
70+ >> > JSONPath(" $.store.book[*][title,price]" ,result_type = " FIELD" ).parse(data)
71+ ```
72+
73+ ``` json
74+ {
75+ "store" : {
76+ "book" : [
77+ {
78+ "title" : " Sayings of the Century" ,
79+ "price" : 8.95
80+ },
81+ {
82+ "title" : " Sword of Honour" ,
83+ "price" : 12.99
84+ },
85+ {
86+ "title" : " Moby Dick" ,
87+ "price" : 8.99
88+ },
89+ {
90+ "title" : " The Lord of the Rings" ,
91+ "price" : 22.99
92+ }
93+ ]
94+ }
95+ }
96+ ```
97+
98+ ### Multi-selection and inverse-selection filtering
99+
100+ ``` python
101+ >> > JSONPath(" $.store.book[?(@.price>8.95 && @.price<=20 || @.title!='Sword of Honour')]" ).parse(data)
102+ ```
103+
104+ ``` json
105+ [
106+ {
107+ "category" : " fiction" ,
108+ "author" : " Herman Melville" ,
109+ "title" : " Moby Dick" ,
110+ "isbn" : " 0-553-21311-3" ,
111+ "price" : 8.99
112+ }
113+ ]
114+ ```
115+
116+ ### Sorting by multiple fields, ascending and descending order
117+
118+ ``` python
119+ >> > JSONPath(" $.store.book[\category,/price]" ).parse(data)
120+ ```
121+
122+ ``` json
123+ [
124+ {
125+ "category" : " reference" ,
126+ "author" : " Nigel Rees" ,
127+ "title" : " Sayings of the Century" ,
128+ "price" : 8.95
129+ },
130+ {
131+ "category" : " fiction" ,
132+ "author" : " Herman Melville" ,
133+ "title" : " Moby Dick" ,
134+ "isbn" : " 0-553-21311-3" ,
135+ "price" : 8.99
136+ },
137+ {
138+ "category" : " fiction" ,
139+ "author" : " Evelyn Waugh" ,
140+ "title" : " Sword of Honour" ,
141+ "price" : 12.99
142+ },
143+ {
144+ "category" : " fiction" ,
145+ "author" : " J. R. R. Tolkien" ,
146+ "title" : " The Lord of the Rings" ,
147+ "isbn" : " 0-395-19395-8" ,
148+ "price" : 22.99
149+ }
150+ ]
151+ ```
0 commit comments