8000 Add quick start to README (fixes #1) · lina1/python-jsonpath-rw@417b301 · GitHub
[go: up one dir, main page]

Skip to content

Commit 417b301

Browse files
committed
Add quick start to README (fixes kennknowles#1)
1 parent 694afb6 commit 417b301

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,49 @@ https://github.com/kennknowles/python-jsonpath-rw
66
[![Build Status](https://travis-ci.org/kennknowles/python-jsonpath-rw.png)](https://travis-ci.org/kennknowles/python-jsonpath-rw)
77

88
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.
910

1011
This library differs from other JSONPath implementations in that it
1112
is a full _language_ implementation, meaning the JSONPath expressions
1213
are first class objects, easy to analyze, transform, parse, print,
1314
and extend. (You can also execute them :-)
1415

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+
1552

1653
JSONPath Syntax
1754
---------------

0 commit comments

Comments
 (0)
0