You are here

protected function FeedsExJmesPathLines::executeSourceExpression in Feeds extensible parsers 7.2

Executes a single source expression.

Parameters

string $machine_name: The source machine name being executed.

string $expression: The expression to execute.

mixed $row: The row to execute on.

Return value

scalar|[]scalar Either a scalar, or a list of scalars. If null, the value will be ignored.

Overrides FeedsExJmesPath::executeSourceExpression

File

src/FeedsExJmesPathLines.inc, line 66
Contains FeedsExJmesPathLines.

Class

FeedsExJmesPathLines
Parses JSON Lines documents with JMESPath.

Code

protected function executeSourceExpression($machine_name, $expression, $row) {

  // Row is a JSON string.
  if ($encoding = $this
    ->detectEncoding($row)) {
    $row = $this
      ->convertEncoding($row, $encoding);
  }
  $row = drupal_json_decode($row);
  $result = $this->jmesPath
    ->search($expression, $row);
  if (is_scalar($result)) {
    return $result;
  }

  // Return a single value if there's only one value.
  return count($result) === 1 ? reset($result) : $result;
}