0

I have the following code that extracts some values from a JSON string, but I want to also apply the prettyPrint() method so that it is more readable. I applied it right in the end, but it obviously does not work. Is there any way to print my extracted response with the prettyPrint method?

Response response = basicAuth.accept(ContentType.JSON).get(uri);
ResponseBody body = response.getBody();
JsonPath json= new JsonPath(body.asString());
String projects = json.getString("projects[1]");

System.out.println("I extracted this project "+projects.prettyPrint());

I also tried this according to the first comment but it's still no good

Response response = basicAuth.accept(ContentType.JSON).get(uri);
ResponseBody body = response.getBody();
JsonPath json= new JsonPath(body.asString());
String projects = json.getString("projects[1]");
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String jsonOutput = gson.toJson(projects);

System.out.println("I extracted this project "+jsonOutput);
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
GetTok
  • 7
  • 3

0 Answers0