c2is / json-extractor
Library for extracting JSON from a string or DomDocument object
Installs: 16 609
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 24
Forks: 0
Open Issues: 0
pkg:composer/c2is/json-extractor
Requires
- php: >=5.3.2
- peekmo/jsonpath: ~2.0@dev
Suggests
- jms/serializer: Useful to subsequently parse the extracted JSON.
This package is auto-updated.
Last update: 2025-10-29 01:56:56 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 |