protected function FeedsJSONPathParser::parseSourceElement in Feeds JSONPath Parser 7
Same name and namespace in other branches
- 6 FeedsJSONPathParser.inc \FeedsJSONPathParser::parseSourceElement()
Parses one item from the context array.
Parameters
array $item: An array containing one item from the context.
string $query: A JSONPath query.
string $source: The source element that corresponds to the query.
Return value
array An array containing the results of the query.
1 call to FeedsJSONPathParser::parseSourceElement()
- FeedsJSONPathParser::parse in ./
FeedsJSONPathParser.inc - Implements FeedsParser::parse().
File
- ./
FeedsJSONPathParser.inc, line 170 - Contains FeedsJSONPathParser.
Class
- FeedsJSONPathParser
- Parses JSON using JSONPath.
Code
protected function parseSourceElement($item, $query, $source) {
if (empty($query)) {
return;
}
$results = $this
->jsonPath($item, $query);
$this
->debug($results, $source);
$count = count($results);
if ($count === 0) {
return;
}
foreach ($results as $delta => $value) {
if (is_string($value) && $value !== '') {
$results[$delta] = !empty($this->config['convert_four_byte']) ? $this
->convertFourBytes($value) : $this
->stripFourBytes($value);
}
}
if ($count === 1) {
return reset($results);
}
return $results;
}