How do I clone an org.json.JSONObject in Java?

Daniel Schaffer picture Daniel Schaffer · Oct 10, 2012 · Viewed 47.1k times · Source

Is there a way to clone an instance of org.json.JSONObject without stringifying it and reparsing the result?

A shallow copy would be acceptable.

Answer

Jaytjuh picture Jaytjuh · Aug 24, 2013

Easiest (and incredibly slow and inefficient) way to do it

JSONObject clone = new JSONObject(original.toString());