https://github.com/tailhook/objpath
A library that allows to traverse data structures by path
https://github.com/tailhook/objpath
Last synced: 11 months ago
JSON representation
A library that allows to traverse data structures by path
- Host: GitHub
- URL: https://github.com/tailhook/objpath
- Owner: tailhook
- License: mit
- Created: 2013-10-22T18:55:24.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-10-30T10:15:46.000Z (over 12 years ago)
- Last Synced: 2025-01-26T07:07:22.352Z (about 1 year ago)
- Language: C
- Size: 109 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
=======
Objpath
=======
Objpath is a library that allows to traverse data structures by path. It can
be used to build fast traversers for JSON and JSON-like data structures (YAML,
msgpack). Potentially may be used to traverse any kind of data structures
which has two kinds of access: based on the key (objects in JSON) and index
(arrays in JSON).
Syntax
======
``/key`` access an object property with name ``key`` (allows only alphanumeric
characters)
``:123`` access an array element with index ``123``
``/*`` traverse all properties of an object
``:*`` traverse all values of an array
``/%`` traverse all keys of the object (traversing keys is usually an
operation that returns the keys itself, its useless to access children of the
key)
``/abc*`` traverse values with keys starting with ``abc``
``:12-34`` traverse all values from 12 up to 34 (including both)
``["abc"]`` access an object property with naem ``abc`` (allows
non-alphanumeric characters)
``A?B`` means that we check whether pattern B matches but return whatever the A
matches
To allow easier concatenation of the patterns, two or more slash characters
are squashed and treated as there was only one.
API
===
The API is designed in a way that adding additional syntax to patterns should
not change the underlying API. However, some optional additions to API may be,
to allow more efficient search. Also the API should be very easy to use from
scripting languages.