I have a JSON string like this:
{"log":"2024-07-04T12:00:57.345665213+02:00 stdout F 2024-07-04 12:00:57,345 TRACE [http-nio-8080-exec-6] org.zalando.logbook.DefaultHttpLogWriter: {"origin":"local","type":"response","correlation":"8c90aa3c5b5bb919","duration":0,"protocol":"HTTP/1.1","status":200,"headers":{"Connection":["close"],"Content-Type":["application/vnd.spring-boot.actuator.v3+json"],"Date":["Thu, 04 Jul 2024 10:00:57 GMT"],"Transfer-Encoding":["chunked"]},"body":{"status":"UP","components":{"diskSpace":{"status":"UP","details":{"total":151490334720,"free":96213721088,"threshold":10485760,"exists":true}},"livenessState":{"status":"UP"},"ping":{"status":"UP"},"readinessState":{"status":"UP"}},"groups":["liveness","readiness"]}}"}
When I try to parse it using:
JsonObject messageObject = JsonParser.parseString(jsonString).getAsJsonObject();
I encounter an Unterminated object error due to nested JSON inside the “log” field. How can I handle situations where a JSON string contains nested JSON inside a field without causing parsing errors? Specifically, I need to extract valid JSON parts (like the inner object in “log”) even if they are nested within another field.