Writing JSON Object as Object not as String to File

I want to write a JSON Object to a file.Currently I have tried using ObjectMapper and Gson but they are writing the JSON as JSONString, Thus the output file has JSON string rather than object. So is there a way JSON Object is written as Object rather than String

JSONObject responseData = new JSONObject(response.getBody().toString());
org.json.simple.JSONObject object  = new
org.json.simple.JSONObject(responseData.toMap());
ObjectMapper objMapper = new ObjectMapper();
objMapper.writeValue(new File(path) , object);

Now the above code is writing the JSON Object as String in to file not a JSONObject.

#java #json

2 Likes1.95 GEEK