Skip to main content

JSON like structure data lookup library. A fast alternative to XPath and JsonPath. Python3 only.

Project description

XJPATH simplifies access to the python data structures using relatively simple path syntax.

A returned element is the actual pointer to the object that can be modified in place if it is possible. However, in case if returned value is a tuple it is a copied list of values that can not be modified. For example a list of dictionary values is a good example.

Let’s assume we have the following data structure:

>>> d = {'data': {
  'a_array': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
  'b_dict': {'a': 'xxx', 'b': 'yyy', 'c': 'zzz'},
  'c_array': [{'v1': 'vdata1'}, {'v2': 'vdata2'}]}}

Get value [‘data’][‘b_dict’][‘a’]:

Function path lookup returns two values. First value is found one, and the second is True if the value is found or False if not.

>>> path_lookup(d, 'data.b_dict.a')
('xxx', True)

Get first element of a_array:

>>> path_lookup(d, 'data.a_array.@first')
(0, True)

Get the last element of a_array:

>>> path_lookup(d, 'data.a_array.@last')
(10, True)

Get a second element of a_array:

>>> path_lookup(d, 'data.a_array.@1')
(1, True)

Get element before the last one:

>>> path_lookup(d, 'data.a_array.@-2')
(9, True)

Get all elements of a_array as non modifiable tuple:

>>> path_lookup(d, 'data.a_array.*')
((1, 2, 3, 4, 5, 6, 7, 8, 9, 0), True)

Get all values of b_dict as a tuple:

>>> path_lookup(d, 'data.b_dict.*')
((1, 2, 3, 4, 5, 6, 7, 8, 9, 0), True)
>>> path_lookup(d, 'data.b_dict.*')
(('yyy', 'zzz', 'xxx'), True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xjpath-0.1.tar.gz (5.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page