Skip to content
Keywan Ghadami edited this page Jun 20, 2020 · 25 revisions

Welcome to the path-expression-languange-for-php wiki!

The language is designed to extract data from nested data structures. And by this also to transformations or calculation on that data.

It can be used as secure low code configuration language, as embedded expression langue in your code or within another language e.g. within the yaml template language.

The Input data can be a nativ php arrays or objects or any mix usually you use it on json or yaml or data.

example input data

the example data will be used as source data for all following example expressions.

All example can be converted to json, php format but I prefere to use yaml because it is easier to write.

convert example to json

person:
  name: Bob
  age: 20
friends:
  - name: Anna
    age: 19
  - name: Fred
    age: 18
  - name: Alice
    age: 19
  - name: Joe
    age: 21
partner:
  name: Luise
  age: 20

Compare to similar languages

Here is a complete overview and a side by side comparison of the syntax elements with languages that influenced this language.

Feature Php Path Expression Languange JMESPath JSONPath Symfony Expression Example Result
child operator person.name Bob
array access operator friends[0].name Anna
function expression
filter expression -
array slice operator -
projection/wildcard -
array - [person.name,person.age] [Bob,20]
hash -
json literals - - `{"foo":1}`.foo 1
flatten - - friends[].age [19,18,19,21]
pipe - -
root element - - friends[?(@.age>=$.person.age)].name Bob
direct numbers - 1 1
arithmetic opertors - - 1+1*2 4
logical operators - - friends[?(@.name="Foo")].age||100 100

Not yet supported features

Priority from 0 to 5 where 0 means no plan to implement

Feature Php Path Expression Languange JMESPath JSONPath Symfony Expression can be replaced?
child operator with numbers 3 - - array access operator
recursive descent 2 - - -
direct float values 0 - - - via json literal
direct exponential numbers 0 - - via json literal
array indices as a set 2 - - slice,array,hash
Bitwise Operators - - -
String contact 4 - -
array index expression 3 - -
Ternary Operators 3 - -
Range Operator 2 - -
Array Contains Operator (✓) (✓) (✓) via filter
method call 1 - -
custom functions 3 ✓* -
access php constants 0 ✓* -
loops (✓) (✓) limited - via projections

✓*=some implementations do not support this

things not supported in any of the query and expression languages

Feature Php Path Expression Languange JMESPath JSONPath Symfony Expression can be replaced?
define functions - - - - -
define methods - - - - -

basic identifier

person will resolved to

name: Bob
age: 20

child operator / sub expressison

expression result
person.age 20

array access operator

expression result
friends[0].name Anna

arithmetic operators

expression result
person.age + person.age 40
person.age * person.age - person.age * (18 + 1) 20

child operator with numbers

in JSONPath you can do foo.1 in JMESPath this is not allowed but can be substituted by using the array index operator: foo[1]