Skip to content

Commit 897a18f

Browse files
committed
feat(docs): update docs
1 parent 4db5c8e commit 897a18f

File tree

3 files changed

+148
-5
lines changed

3 files changed

+148
-5
lines changed

Makefile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
OK_COLOR=\033[32;01m
2+
NO_COLOR=\033[0m
3+
4+
all: lint unit
5+
6+
export PYTHONPATH:=${PWD}
7+
version=`python -c 'import jsonpath_ng; print(jsonpath_ng.__version__)'`
8+
filename=jsonpath_ng-`python -c 'import jsonpath_ng; print(jsonpath_ng.__version__)'`.tar.gz
9+
10+
apidocs:
11+
@sphinx-apidoc -f --follow-links -H "API documentation" -o docs/source jsonpath_ng
12+
13+
htmldocs:
14+
@rm -rf docs/_build
15+
$(MAKE) -C docs html
16+
17+
install:
18+
@pip install -r requirements.txt
19+
@pip install -r requirements-dev.txt
20+
21+
lint:
22+
@echo "$(OK_COLOR)==> Linting code ...$(NO_COLOR)"
23+
@flake8 .
24+
25+
test: clean lint
26+
@echo "$(OK_COLOR)==> Runnings tests ...$(NO_COLOR)"
27+
@py.test -s -v --capture sys --cov jsonpath_ng --cov-report term-missing
28+
29+
coverage:
30+
@coverage run --source jsonpath_ng -m py.test
31+
@coverage report
32+
33+
tag:
34+
@echo "$(OK_COLOR)==> Creating tag $(version) ...$(NO_COLOR)"
35+
@git tag -a "v$(version)" -m "Version $(version)"
36+
@echo "$(OK_COLOR)==> Pushing tag $(version) to origin ...$(NO_COLOR)"
37+
@git push origin "v$(version)"
38+
39+
bump:
40+
@bumpversion --commit --tag --current-version $(version) patch jsonpath_ng/__init__.py --allow-dirty
41+
42+
bump-minor:
43+
@bumpversion --commit --tag --current-version $(version) minor jsonpath_ng/__init__.py --allow-dirty
44+
45+
history:
46+
@git changelog --tag $(version)
47+
48+
clean:
49+
@echo "$(OK_COLOR)==> Cleaning up files that are already in .gitignore...$(NO_COLOR)"
50+
@for pattern in `cat .gitignore`; do find . -name "*/$$pattern" -delete; done
51+
52+
publish:
53+
@echo "$(OK_COLOR)==> Releasing package ...$(NO_COLOR)"
54+
@python setup.py register
55+
@python setup.py sdist upload
56+
@python setup.py bdist_wheel --universal upload
57+
@rm -fr build dist .egg jsonpath_ng.egg-info

README.rst

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Python JSONPath Next-Generation
44
A final implementation of JSONPath for Python, including arithmetic
55
and binary comparison operators, as defined in the original `JSONPath proposal`_.
66

7+
This packages merges both `jsonpath-rw`_ and `jsonpath-rw-ext`_ and
8+
provides several AST API enhancements, such as the ability to update or removes nodes in the tree.
9+
10+
About
11+
-----
12+
713
This library provides a robust and significantly extended implementation
814
of JSONPath for Python. It is tested with Python 2.6, 2.7, 3.2, 3.3.
915

@@ -19,7 +25,7 @@ To install, use pip:
1925

2026
::
2127

22-
$ pip install git+git://github.com/tomas-fp/python-jsonpath-ng.git#egg=jsonpath-ng
28+
$ pip install --upgrade jsonpath-ng
2329

2430
Then:
2531

@@ -56,6 +62,18 @@ Then:
5662
>>> jsonpath_expr_direct = Fields('foo').child(Slice('*')).child(Fields('baz')) # This is equivalent
5763
5864
65+
Using the extended parser:
66+
67+
.. code:: python
68+
69+
$ python
70+
71+
>>> from jsonpath_ng.ext import parse
72+
73+
# A robust parser, not just a regex. (Makes powerful extensions possible; see below)
74+
>>> jsonpath_expr = parse('foo[*].baz')
75+
76+
5977
JSONPath Syntax
6078
---------------
6179

@@ -144,8 +162,9 @@ easy to do so directly, and here are some examples:
144162
- ``Where(Slice(), Fields('subfield'))``
145163
- ``Descendants(jsonpath, jsonpath)``
146164

147-
Extensions
148-
----------
165+
166+
Extras
167+
------
149168

150169
- *Path data*: The result of ``JsonPath.find`` provide detailed context
151170
and path data so it is easy to traverse to parent objects, print full
@@ -160,6 +179,69 @@ Extensions
160179
contained in backquotes can be made to be a new operator, currently
161180
by extending the library.
162181

182+
183+
Extensions
184+
----------
185+
186+
+--------------+----------------------------------------------+
187+
| name | Example |
188+
+==============+==============================================+
189+
| len | - $.objects.`len` |
190+
+--------------+----------------------------------------------+
191+
| sub | - $.field.`sub(/foo\\\\+(.*)/, \\\\1)` |
192+
+--------------+----------------------------------------------+
193+
| split | - $.field.`split(+, 2, -1)` |
194+
| | - $.field.`split(sep, segement, maxsplit)` |
195+
+--------------+----------------------------------------------+
196+
| sorted | - $.objects.`sorted` |
197+
| | - $.objects[\\some_field] |
198+
| | - $.objects[\\some_field,/other_field] |
199+
+--------------+----------------------------------------------+
200+
| filter | - $.objects[?(@some_field > 5)] |
201+
| | - $.objects[?some_field = "foobar")] |
202+
| | - $.objects[?some_field > 5 & other < 2)] |
203+
+--------------+----------------------------------------------+
204+
| arithmetic | - $.foo + "_" + $.bar |
205+
| (-+*/) | - $.foo * 12 |
206+
| | - $.objects[*].cow + $.objects[*].cat |
207+
+--------------+----------------------------------------------+
208+
209+
About arithmetic and string
210+
---------------------------
211+
212+
Operations are done with python operators and allows types that python
213+
allows, and return [] if the operation can be done due to incompatible types.
214+
215+
When operators are used, a jsonpath must be be fully defined otherwise
216+
jsonpath-rw-ext can't known if the expression is a string or a jsonpath field,
217+
in this case it will choice string as type.
218+
219+
Example with data::
220+
221+
{
222+
'cow': 'foo',
223+
'fish': 'bar'
224+
}
225+
226+
| **cow + fish** returns **cowfish**
227+
| **$.cow + $.fish** returns **foobar**
228+
| **$.cow + "_" + $.fish** returns **foo_bar**
229+
| **$.cow + "_" + fish** returns **foo_fish**
230+
231+
About arithmetic and list
232+
-------------------------
233+
234+
Arithmetic can be used against two lists if they have the same size.
235+
236+
Example with data::
237+
238+
{'objects': [
239+
{'cow': 2, 'cat': 3},
240+
{'cow': 4, 'cat': 6}
241+
]}
242+
243+
| **$.objects[\*].cow + $.objects[\*].cat** returns **[6, 9]**
244+
163245
More to explore
164246
---------------
165247

@@ -211,6 +293,7 @@ Copyright and License
211293
---------------------
212294

213295
Copyright 2013 - Kenneth Knowles
296+
Copyright 2017 - Tomas Aparicio
214297

215298
Licensed under the Apache License, Version 2.0 (the "License"); you may
216299
not use this file except in compliance with the License. You may obtain
@@ -227,6 +310,9 @@ See the License for the specific language governing permissions and
227310
limitations under the License.
228311

229312
.. _`JSONPath proposal`: http://goessner.net/articles/JsonPath/
313+
.. _`jsonpath-rw`: https://github.com/kennknowles/python-jsonpath-rw
314+
.. _`jsonpath-rw-ext`: https://pypi.python.org/pypi/jsonpath-rw-ext/
315+
230316
.. |Build Status| image:: https://travis-ci.org/kennknowles/python-jsonpath-ng.png?branch=master
231317
:target: https://travis-ci.org/kennknowles/python-jsonpath-ng
232318
.. |Test coverage| image:: https://coveralls.io/repos/kennknowles/python-jsonpath-ng/badge.png?branch=master

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
'A robust and significantly extended implementation '
1010
'of JSONPath for Python, with a clear AST for metaprogramming.'
1111
),
12-
author='Kenneth Knowles',
13-
author_email='kenn.knowles@gmail.com',
12+
author='Tomas Aparicio',
13+
author_email='tomas@aparicio.me',
1414
url='https://github.com/tomas-fp/python-jsonpath-ng',
1515
license='Apache 2.0',
1616
long_description=io.open('README.rst', encoding='utf-8').read(),

0 commit comments

Comments
 (0)