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

Method jsonParser

lib/Datasource/ExternalJson.php:150–177  ·  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

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