Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
}
},
"require": {
"php": ">=5.4.0"
"php": ">=5.4.0",
"ext-json": "*"
},
"require-dev": {
"peekmo/jsonpath": "dev-master",
Expand Down
2 changes: 1 addition & 1 deletion src/Flow/JSONPath/Filters/QueryMatchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class QueryMatchFilter extends AbstractFilter
{
const MATCH_QUERY_OPERATORS = '
@(\.(?<key>\w+)|\[["\']?(?<keySquare>.*?)["\']?\])
@(\.(?<key>[^ =]+)|\[["\']?(?<keySquare>.*?)["\']?\])
(\s*(?<operator>==|=|<>|!==|!=|>|<)\s*(?<comparisonValue>.+))?
';

Expand Down
35 changes: 35 additions & 0 deletions tests/JSONPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,18 @@ public function testRecursiveWithQueryMatch()
$this->assertEquals(['0-553-21311-3', '0-395-19395-8'], $result->data());
}

/**
* .data.tokens[?(@.Employee.FirstName)]
* Verify that it is possible to filter with a key containing punctuation
*/
public function testRecursiveWithQueryMatchWithDots()
{
$result = (new JSONPath($this->exampleDataWithDots(rand(0, 1))))->find(".data.tokens[?(@.Employee.FirstName)]");
$result = json_decode(json_encode($result), true);

$this->assertEquals([['Employee.FirstName' => 'Jack']], $result);
}

/**
* $..*
* All members of JSON structure
Expand Down Expand Up @@ -603,6 +615,29 @@ public function exampleDataWithSlashes($asArray = true)
return json_decode($json, $asArray);
}

public function exampleDataWithDots($asArray = true)
{
$json = '
{
"data": {
"tokens": [
{
"Employee.FirstName": "Jack"
},
{
"Employee.LastName": "Daniels"
},
{
"Employee.Email": "jd@example.com"
}
]
}
}
';

return json_decode($json, $asArray);
}

public function exampleDataWithSimpleIntegers($asArray = true)
{
$json = '
Expand Down