FlowCommunications/JSONPath

can't parse by tokens with dash in name

oizdar opened this issue · 6 comments

For e.g.: $.data.*

I'm using this in codeception. In:
$I->seeResponseMatchesJsonType(Schemas::$issue, '$.data.*');

I've get an exception:
[Flow\JSONPath\JSONPathException] Unable to parse token php-logger in expression: .data.php-logger

I tried also:

  • $.data["php-logger"]
  • $.data[php-logger]
  • $.data[]

For each same result.

Same problem here. There doesn't seem to be an obvious way on the tokenizer to modify the "slice" regex in a way that doesn't mess up the negative index detection...

same for me. @stephenfrank @twistor any update on this?

The solution to this is to use quotes, like this:

$I->seeResponseJsonMatchesJsonPath('$.data.[*].relationships."some-attribute"');

@millsoft solution with quotes works.

Had same problem on following code:

<?php

use Flow\JSONPath\JSONPath;

require_once './vendor/autoload.php';

$path = '[feedback_data][57246a5e-af86-11e8-bff0-00155d085515][question_answer_uuid]';
$data = ['feedback_data' => ['57246a5e-af86-11e8-bff0-00155d085515' => ['question_answer_uuid' => '57246a5e-af86-11e8-bff0-00155d085515']]];

$json = (new JSONPath($data))->find($path)->data();

var_dump($json);

but there are cases when it's working (when UUID is different)

Unable to parse token movement-of-money in expression: .some.key-with-dash

/var/www/app/vendor/flow/jsonpath/src/Flow/JSONPath/JSONPathLexer.php:222
/var/www/app/vendor/flow/jsonpath/src/Flow/JSONPath/JSONPathLexer.php:135
/var/www/app/vendor/flow/jsonpath/src/Flow/JSONPath/JSONPathLexer.php:155
/var/www/app/vendor/flow/jsonpath/src/Flow/JSONPath/JSONPath.php:140
/var/www/app/vendor/flow/jsonpath/src/Flow/JSONPath/JSONPath.php:39
/var/www/app/tests/Unit/JsonPathTest.php:49

But on https://jsonpath.com/ key-with-dash works.

@4n70w4 @millsoft @oizdar please take a look at #36