Skip to content

Commit 9b0b033

Browse files
committed
docs: update readme
1 parent 14da85e commit 9b0b033

File tree

2 files changed

+49
-45
lines changed

2 files changed

+49
-45
lines changed

README.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
- [jsonpath-python](#jsonpath-python)
55
- [Features](#features)
6+
- [Issues](#issues)
67
- [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)
8+
- [Filter](#filter)
9+
- [Sort](#sort)
10+
- [Output mode: FIELD (In progress)](#output-mode-field-in-progress)
1011

1112
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1213

@@ -17,13 +18,12 @@ A more powerful JSONPath implementations in modern python.
1718
## Features
1819

1920
- [x] Light. (No need to install third-party dependencies.)
20-
- [ ] Support fields-extractor.
21-
- [ ] Powerful filtering function, including multi-selection, inverse-selection filtering.
22-
- [ ] Powerful sorting function, including sorting by multiple fields, ascending and descending order.
23-
24-
## Issues
25-
26-
- Not support parent operator.
21+
- [x] Powerful filtering function, including multi-selection, inverse-selection filtering.
22+
- [x] Powerful sorting function, including sorting by multiple fields, ascending and descending order.
23+
- [x] Support output mode: VALUE
24+
- [ ] Support output mode: PATH
25+
- [ ] Support output mode: FIELD
26+
- [ ] Support parent operator
2727

2828
## Examples
2929

@@ -68,41 +68,10 @@ data = {
6868
}
6969
```
7070

71-
### Fields-Extractor
72-
73-
```python
74-
>>> JSONPath("$.store.book[*][title,price]",result_type="FIELD").parse(data)
75-
```
76-
77-
```json
78-
{
79-
"store": {
80-
"book": [
81-
{
82-
"title": "Sayings of the Century",
83-
"price": 8.95
84-
},
85-
{
86-
"title": "Sword of Honour",
87-
"price": 12.99
88-
},
89-
{
90-
"title": "Moby Dick",
91-
"price": 8.99
92-
},
93-
{
94-
"title": "The Lord of the Rings",
95-
"price": 22.99
96-
}
97-
]
98-
}
99-
}
100-
```
101-
102-
### Multi-selection and inverse-selection filtering
71+
### Filter
10372

10473
```python
105-
>>> JSONPath("$.store.book[?(@.price>8.95 && @.price<=20 || @.title!='Sword of Honour')]").parse(data)
74+
>>> JSONPath('$.store.book[?(@.price>8.95 and @.price<=20 and @.title!="Sword of Honour")]').parse(data)
10675
```
10776

10877
```json
@@ -117,10 +86,10 @@ data = {
11786
]
11887
```
11988

120-
### Sorting by multiple fields, ascending and descending order
89+
### Sorter
12190

12291
```python
123-
>>> JSONPath("$.store.book[\category,/price]").parse(data)
92+
>>> JSONPath("$.store.book[/(~category,price)]").parse(data)
12493
```
12594

12695
```json
@@ -153,3 +122,34 @@ data = {
153122
}
154123
]
155124
```
125+
126+
### Field-Extractor (In progress)
127+
128+
```python
129+
>>> JSONPath("$.store.book[*][title,price]",result_type="FIELD").parse(data)
130+
```
131+
132+
```json
133+
{
134+
"store": {
135+
"book": [
136+
{
137+
"title": "Sayings of the Century",
138+
"price": 8.95
139+
},
140+
{
141+
"title": "Sword of Honour",
142+
"price": 12.99
143+
},
144+
{
145+
"title": "Moby Dick",
146+
"price": 8.99
147+
},
148+
{
149+
"title": "The Lord of the Rings",
150+
"price": 22.99
151+
}
152+
]
153+
}
154+
}
155+
```

test/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
TestCase("$[book]", data, [data["book"]]),
1717
TestCase("$.'a.b c'", data, [data["a.b c"]]),
1818
TestCase("$['a.b c']", data, [data["a.b c"]]),
19+
# recursive descent
1920
TestCase("$..price", data, [8.95, 12.99, 8.99, 22.99, 19.95]),
21+
# slice
2022
TestCase("$.book[1:3]", data, data["book"][1:3]),
2123
TestCase("$.book[1:-1]", data, data["book"][1:-1]),
2224
TestCase("$.book[0:-1:2]", data, data["book"][0:-1:2]),
2325
TestCase("$.book[-1:1]", data, data["book"][-1:1]),
2426
TestCase("$.book[-1:-11:3]", data, data["book"][-1:-11:3]),
2527
TestCase("$.book[:]", data, data["book"][:]),
28+
# filter
2629
TestCase("$.book[?(@.price>8 and @.price<9)].price", data, [8.95, 8.99]),
2730
TestCase('$.book[?(@.category=="reference")].category', data, ["reference"]),
2831
TestCase(
@@ -35,6 +38,7 @@
3538
data,
3639
["Evelyn Waugh", "Herman Melville"],
3740
),
41+
# sort
3842
TestCase("$.book[/(price)].price", data, [8.95, 8.99, 12.99, 22.99]),
3943
TestCase("$.book[/(~price)].price", data, [22.99, 12.99, 8.99, 8.95]),
4044
TestCase("$.book[/(category,price)].price", data, [8.99, 12.99, 22.99, 8.95]),

0 commit comments

Comments
 (0)