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

Method jsonParser

lib/Datasource/LocalJson.php:114–142  ·  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

112 * @return array
113 */
114 private function jsonParser($option, $rawResult): array {
115 $pathString = $option['path'];
116 $json = $this->decodeJsonInput($rawResult);
117
118 // Check for array extraction pattern (e.g., {BTC,tmsp,price})
119 $arrayFields = $this->extractArrayFields($pathString);
120
121 if (!empty($arrayFields)) {
122 // Handle absolute path before array fields (e.g., data/data{from,to,intensity/forecast})
123 $json = $this->extractAbsolutePathIfPresent($json, $pathString);
124
125 // Normalize paths and ensure at least 3 columns
126 $paths = $this->normalizePaths($arrayFields, 3, 'empty');
127 $data = $this->extractRowsFromArray($json, $paths);
128 } else {
129 // Single value extraction (e.g., data/currentHashrate,data/averageHashrate)
130 $paths = array_map('trim', explode(',', $pathString));
131 $data = $this->extractSingleValues($json, $paths);
132 }
133
134 // Derive header from paths (use last segment for each path)
135 $header = array_map([$this, 'getHeaderFromPath'], $paths);
136
137 return [
138 'header' => $header,
139 'dimensions' => array_slice($header, 0, count($header) - 1),
140 'data' => $data,
141 ];
142 }
143
144 /**
145 * 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