MCPcopy Create free account
hub / github.com/Rello/analytics / jsonParser

Method jsonParser

lib/Datasource/ExternalJson.php:155–182  ·  view source on GitHub ↗

* Parses JSON data based on the provided options and raw input. * * @param array $option * @param string $rawResult * @return array */

($option, $rawResult)

Source from the content-addressed store, hash-verified

153 * @return array
154 */
155 private function jsonParser($option, $rawResult): array {
156 $pathString = $option['path'];
157 $json = $this->decodeJsonInput($rawResult);
158
159 // Check for array extraction pattern (e.g., {BTC,tmsp,price})
160 $arrayFields = $this->extractArrayFields($pathString);
161 if (!empty($arrayFields)) {
162 // Handle absolute path before array fields (e.g., data/data{from,to,intensity/forecast})
163 $json = $this->extractAbsolutePathIfPresent($json, $pathString);
164
165 // Normalize paths and ensure at least 3 columns
166 $paths = $this->normalizePaths($arrayFields, 3, 'empty');
167 $data = $this->extractRowsFromArray($json, $paths);
168 } else {
169 // Single value extraction (e.g., data/currentHashrate,data/averageHashrate)
170 $paths = array_map('trim', explode(',', $pathString));
171 $data = $this->extractSingleValues($json, $paths);
172 }
173
174 // Derive header from paths (use last segment for each path)
175 $header = array_map([$this, 'getHeaderFromPath'], $paths);
176
177 return [
178 'header' => $header,
179 'dimensions' => array_slice($header, 0, count($header) - 1),
180 'data' => $data,
181 ];
182 }
183
184 /**
185 * Decode JSON input, supporting both standard and line-delimited JSON.

Callers 1

readDataMethod · 0.95

Calls 7

decodeJsonInputMethod · 0.95
extractArrayFieldsMethod · 0.95
normalizePathsMethod · 0.95
extractRowsFromArrayMethod · 0.95
extractSingleValuesMethod · 0.95
countFunction · 0.50

Tested by

no test coverage detected