Download the PHP package galbar/jsonpath without Composer

On this page you can find all versions of the php package galbar/jsonpath. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package jsonpath

JsonPath

Build Status Coverage Status Latest Stable Version License

This is a JSONPath implementation for PHP.

This implementation features all elements in the specification except the () operator (in the spcecification there is the $..a[(@.length-1)], but this can be achieved with $..a[-1] and the latter is simpler).

In case of no matches for the query it will return an empty array.

Features

This implementation has the following features:

Installation

To install JsonPath you will need to be using Composer in your project. To install it please see the docs.

Usage

In every file you use it add:

Now you can create an instance of JsonObject and use it:

SmartGet

When creating a new instance of JsonObject, you can pass a second parameter to the constructor. This sets the behaviour of the instance to use SmartGet.

What SmartGet does is to determine if the given JsonPath branches at some point, if it does it behaves as usual; otherwise, it will directly return the value pointed by the given path (not the array containing it) or false if not found.

GetJsonObjects

Sometimes you need to access multiple values of a subobject that has a long prefix (p.e. $.a.very.long.prefix.for.[*].object), in this case you would first get said object and make a JsonObject of it and then access its properties.

Now if you want to edit the object (set or add values) and want these changes to affect the original object, the way of doing this is by using JsonObject::getJsonObjects($jsonpath). This method works the same way get does, but it will return the results as JsonObject instances containing a reference to the value in the source JsonObject.

JsonPath Language

This library implements the following specification:

¹var_name: the regex roughly translates to "any valid JavaScript variable name", plus some quirks such as names starting with numbers or containing dashes (-).

Limitations on the specification:

The .length operator can be used to:

The comparators:
==, !=, <, >, <=, >= do what expected (compare by type and value).
=~ is a regex comparator, matches the left operand with the pattern in the right operand. The value on the left must be a string and on the right regpattern. Other wise returns false.

JsonPath Example

Consider the following json:

JsonPath Result
$.store.bicycle.price The price of the bicycle.
$.store.book[*] All books.
$.store.book[1,3] The second and fourth book.
$.store.book[1:3] From the second book to the third.
$.store.book[:3] From the first book to the third.
$.store.book[x:y:z] Books from x to y with a step of z.
$..book[?(@.category == 'fiction')] All books with category == 'fiction'.
$..*[?(@.available == true)].price All prices of available products.
$..book[?(@.price < 10)].title The title of all books with price lower than 10.
$..book[?(@.author==$.authors[3])] All books by "J. R. R. Tolkien"
$[store] The store.
$['store'] The store.
$..book[*][title, 'category', "author"] title, category and author of all books.
$..book[?(@.author in [$.authors[0], $.authors[2]])] All books by "Nigel Rees" or "Herman Melville".
$.store.book[?(@.category == 'fiction' and @.price < 10 or @.color == "red")].price Books of fiction with a price lower than 10 or something with of color red. (and takes precedence to or)

See more examples in the ./tests/Galbar/JsonPath folder.

Test

To run tests, from the project root folder:
php app/test.php <jsonpath> [<file to json file>]

If no json file is given it defaults to the json object described previously in this file.

For example:
php app/test.php "$..*[?(@.category == 'fiction' and @.price < 10 or @.color == \"red\")].price"
Result should be:
[19.95,8.99]

Ready to code

you can open the project in your browser and can start coding Gitpod ready-to-code

Docs

To generate the docs, from the project root folder:
php vendor/bin/sami.php update app/docgen.php


All versions of jsonpath with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package galbar/jsonpath contains the following files

Loading the files please wait ....