The toString methods of JSONObject and JSONArray are not very fast, mostly because of the usage of StringWriter and the generic code to support an indent, although in the default toString case it is always 0.
My suggestion is to improve the performance for the default toString method without indent by duplicating by using a StringBuilderinstead of a StringWriter.
The toString methods of JSONObject and JSONArray are not very fast, mostly because of the usage of
StringWriter
and the generic code to support an indent, although in the default toString case it is always 0.You can compare the performance of the library e.g. with this comparison project, which also list the results in a graph: https://github.com/fabienrenaud/java-json-benchmark?tab=readme-ov-file#users-model
My suggestion is to improve the performance for the default toString method without indent by duplicating by using a
StringBuilder
instead of aStringWriter
.