RETIRED, further work has moved to Debian project infrastructure
Go to file
Mehdi Abaakouk 42cfd7cb8b Fix pep8 2016-03-10 10:37:41 +01:00
doc/source Fix package name 2015-08-18 17:53:43 +02:00
jsonpath_rw_ext Fix pep8 2016-03-10 10:37:41 +01:00
.coveragerc Initial Commit. 2015-08-18 16:27:00 +02:00
.gitignore Initial Commit. 2015-08-18 16:27:00 +02:00
.gitreview Initial Commit. 2015-08-18 16:27:00 +02:00
.mailmap Initial Commit. 2015-08-18 16:27:00 +02:00
.testr.conf Initial Commit. 2015-08-18 16:27:00 +02:00
.travis.yml Remove py32, mock is not supported 2015-08-18 17:26:55 +02:00
CONTRIBUTING.rst Initial Commit. 2015-08-18 16:27:00 +02:00
HACKING.rst Fix package name 2015-08-18 17:53:43 +02:00
LICENSE Initial Commit. 2015-08-18 16:27:00 +02:00
MANIFEST.in Initial Commit. 2015-08-18 16:27:00 +02:00
README.rst Fix README 2015-09-16 23:58:57 +02:00
babel.cfg Initial Commit. 2015-08-18 16:27:00 +02:00
openstack-common.conf Initial Commit. 2015-08-18 16:27:00 +02:00
releases.sh Ensure pep8,py27,py34 pass before releasing 2015-08-22 17:50:16 +02:00
requirements.txt Set minimum version of jsonpath-rw 2015-12-08 12:12:47 +01:00
setup.cfg Fix package name 2015-08-18 17:53:43 +02:00
setup.py Initial Commit. 2015-08-18 16:27:00 +02:00
test-requirements.txt Initial Commit. 2015-08-18 16:27:00 +02:00
tox.ini Initial Commit. 2015-08-18 16:27:00 +02:00

README.rst

python-jsonpath-rw-ext

image

Latest Version

Downloads

Extensions for JSONPath RW

jsonpath-rw-ext extends json-path-rw capabilities by adding multiple extensions. 'len' that allows one to get the length of a list. 'sorted' that returns a sorted version of a list, 'arithmetic' that permits one to make math operation between elements and 'filter' to select only certain elements of a list.

Each extensions will be proposed upstream and will stay here only if they are refused.

Quick Start

At the command line:

$ pip install jsonpath-rw-ext

Or, if you have virtualenvwrapper installed:

$ mkvirtualenv jsonpath-rw-ext
$ pip install jsonpath-rw-ext

To replace the jsonpath_rw parser by this one with:

import jsonpath_rw_ext
jsonpath_rw_ext.parse("$.foo").find(...)

Or:

from jsonpath_rw_ext import parser
parser.ExtentedJsonPathParser().parse("$.foo").find(...)

The jsonpath classes are not part of the public API, because the name/structure can change when they will be implemented upstream. Only the syntax shouldn't change.

Extensions

name Example
len
  • $.objects.len
sub
  • $.field.sub(/foo+(.*)/, 1)
split
  • $.field.split(+, 2, -1)
  • $.field.split(sep, segement, maxsplit)
sorted
  • $.objects.sorted
  • $.objects[\some_field]
  • $.objects[\some_field,/other_field]
filter
  • $.objects[?(@some_field > 5)]
  • $.objects[?some_field = "foobar")]
  • $.objects[?some_field > 5 & other < 2)]
arithmetic (-+*/)
  • $.foo + "_" + $.bar
  • $.foo * 12
  • $.objects[].cow + $.objects[].cat

About arithmetic and string

Operations are done with python operators and allows types that python allows, and return [] if the operation can be done due to incompatible types.

When operators are used, a jsonpath must be be fully defined otherwise jsonpath-rw-ext can't known if the expression is a string or a jsonpath field, in this case it will choice string as type.

Example with data:

{
    'cow': 'foo',
    'fish': 'bar'
}
cow + fish returns cowfish
$.cow + $.fish returns foobar
$.cow + "_" + $.fish returns foo_bar
$.cow + "_" + fish returns foo_fish

About arithmetic and list

Arithmetic can be used against two lists if they have the same size.

Example with data:

{'objects': [
    {'cow': 2, 'cat': 3},
    {'cow': 4, 'cat': 6}
]}
$.objects[*].cow + $.objects[*].cat returns [6, 9]