I want to read a JSON file and get its content in the String variable. But, I'm getting escape characters like "\n" in it. How to read a JSON without these characters?
Input: any formatted JSON file
What I've tried:
String content = new String(Files.readAllBytes(<file_path>));
- Using JsonReader, it's giving error "JsonReader at line 1 column 1 path $"
Gson gson = new Gson();
JsonReader reader = new JsonReader(Files.newBufferedReader(<file_path>));
String content = gson.fromJson(reader, String.class);
Solution
String content = new String(Files.readAllBytes(<file_path>));
JSONObject obj = new JSONObject(content);
String formattedString = obj.toString();