| Did you know ... | Search Documentation: |
| Pack logtalk -- logtalk-3.101.0/docs/handbook/_sources/libraries/json_path.rst.txt |
.. _library_json_path:
json_pathThis library provides predicates for parsing, generating, and evaluating JSONPath queries for native Logtalk JSON terms.
It is based on RFC 9535:
This implementation currently supports:
||, &&, and !length(), count(), match(),
search(), and value()., character classes, single-character escapes, and quantifiers
(*, +, ?, {m}, {m,}, {m,n})\p{...} and \P{...} using
backend unicode_property/2 support when availablecodes(...) representation
contain only Unicode scalar valuesOpen the `../../apis/library_index.html#json_path <../../apis/library_index.html#json_path>`__ link in a web browser.
To load all entities in this library, load the loader.lgt file:
::
| ?- logtalk_load(json_path(loader)).
To test this library predicates, load the tester.lgt file:
::
| ?- logtalk_load(json_path(tester)).
The library defines the json_path(_Representation_) parametric
object where _Representation_ can be one of:
atom - member names and normalized paths are represented as atomschars - member names and normalized paths are represented as
chars(List)codes - member names and normalized paths are represented as
codes(List)
When using the default json_path object, member names and normalized
paths are represented as atoms.
Parse and evaluate a query:
::
| ?- json_path::parse(atom('$.store.book[0].title'), Query),
json_path::evaluate(Query, {store-{book-[{title-'Sayings of the Century'}]}}, Values).
Query = json_path([child([name(store)]), child([name(book)]), child([index(0)]), child([name(title)])])
Values = ['Sayings of the Century']
yes
Filter books by price:
::
| ?- JSON = {store-{book-[{title-'Sayings', price-8.95}, {title-'Honour', price-12.99}]}},
json_path::query(atom('$.store.book[?@.price < 10].title'), JSON, Values).
JSON = {store-{book-[{title-'Sayings', price-8.95}, {title-'Honour', price-12.99}]}}
Values = ['Sayings']
yes
Return normalized paths for the selected nodes:
::
| ?- json_path::parse(atom('$..j'), Query),
json_path::paths(Query, {o-{j-1}, a-[[{j-4}]]}, Paths).
Paths = ['$[''o''][''j'']', '$[''a''][0][0][''j'']']
yes