json-flattener icon indicating copy to clipboard operation
json-flattener copied to clipboard

Is there any configuration available to speed up Flatten and Unflatten JSON?

Open vsachinv opened this issue 1 year ago • 1 comments

We have pretty big JSON files which contains sometimes more than 180k nodes as well. We have done comparision with https://github.com/spring-projects/spring-vault/blob/main/spring-vault-core/src/main/java/org/springframework/vault/support/JsonMapFlattener.java api and found JSONFlattern is almost taking 5 times time. Is there any config available to speed up the same which can be tweaked and also Unfllatten is also taking alot time even after applying latest build.

vsachinv avatar Jun 08 '23 08:06 vsachinv

There is a main difference between json-flattener and Spring JsonMapFlattener. Spring JsonMapFlattener processes Java Map directly, but json-flattener does JSON processing at first. This difference results in performance comparison.

However json-flattener adopts json-base as implementation interfaces which supports org.json natively, therefore add org.json into your dependencies, then you can do something like this:

JsonFlattener jf = new JsonFlattener(new OrgJsonValue(new JSONObject(map)));

Because org.json uses most Java native objects internally, this approach should increase the performance you wish to gain.

wnameless avatar Jul 05 '23 00:07 wnameless