Change the java JSONFormatter to handle embedding text in the report correctly

The java JSONFormatter does not handle calls to write() correctly. The formatter expects them after the result() call, but if a step definition uses write() calls to embed text in the report, they will occur after the match() call but before the result() call.
This is the root cause of the following issue in Cucumber-JVM: https://github.com/cucumber/cucumber-jvm/issues/565
Change the java JSONFormatter so that it can handle calls to write() after the call to match() but before the call to result().