Skip to content

Commit ac91a49

Browse files
author
Quentin Schmick
authored
Merge pull request #1 from always-open/feature/parse-encoded-json
Added recursive parsing of json strings
2 parents 2b3dec8 + ee4e957 commit ac91a49

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Observers/RequestLogObserver.php

+16
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,21 @@ public function saving(RequestLogBaseModel $model)
1111
if (null === $model->occurred_at) {
1212
$model->occurred_at = now();
1313
}
14+
15+
$model->body = $this->parsePossibleJson($model->body);
16+
$model->response = $this->parsePossibleJson($model->response);
17+
}
18+
19+
protected function parsePossibleJson(null|array|string|object $possibleJson) : null|array|string|object
20+
{
21+
while (
22+
is_string($possibleJson)
23+
&& ! empty($possibleJson)
24+
&& ($parsed_json = json_decode($possibleJson, true)) !== null
25+
) {
26+
$possibleJson = $parsed_json;
27+
}
28+
29+
return $possibleJson;
1430
}
1531
}

0 commit comments

Comments
 (0)