I have two different(separate) json format response and I am doing a search for element with values in each.
Using this method to evaluate if the expression is valid/invalid:
public function evaluate(Json $json, $expression)
{
if ($this->evaluationMode === 'javascript') {
$expression = str_replace('->', '.', $expression);
}
try {
return $json->read($expression, $this->propertyAccessor);
} catch (\Exception $e) {
throw new \Exception(sprintf('Failed to evaluate expression "%s"', $expression), 0, $e);
}
}
One example starts with a curly braces which I believe an object.
{
"nid": [
{
"value": 10278
}
],
...
}
and I was able to access the nid
value by typing nid[0].value
However, when I have a json response that is enclosed in []
:
[
{
"test": "test",
"title": "title"
},
...
]
I dont get a valid expression when I try test
Other examples that is valid and invalid:
VALID by accessing data.type
, displays article
{
"data": {
"type": "article",
"id": "123",
...
}
}
INVALID expression, tried id[0].value
or id.value
[
{
"id": [
{
"value": 398
}
],
...
}
]