c2is/json-extractor

Library for extracting JSON from a string or DomDocument object

v1.0.1 2016-04-15 13:34 UTC

This package is auto-updated.

Last update: 2024-03-29 02:31:14 UTC


README

This library allows you to extract Json from a string/json/array using JsonPath.

JSONPath Examples

JSONPath Result
$.store.books[\*].author the authors of all books in the store
$..author all authors
$.store..price the price of everything in the store.
$..books[2] the third book
$..books[(@.length-1)] the last book in order.
$..books[0,1] the first two books
$..books[:2] the first two books
$..books[?(@.isbn)] filter all books with isbn number
$..books[?(@.price<10)] filter all books cheapier than 10
$..* all elements in the data (recursively extracted)

Expression syntax

Symbol Description
$ The root object/element (not strictly necessary)
@ The current object/element
. or [] Child operator
.. Recursive descent
* Wildcard. All child elements regardless their index.
[,] Array indices as a set
[start:end:step] Array slice operator borrowed from ES4/Python.
?() Filters a result set by a script expression
() Uses the result of a script expression as the index