Skip to content

Commit 6ede5ae

Browse files
committed
Pretty print JSON
1 parent e7411d6 commit 6ede5ae

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/java/io/simplelocalize/cli/client/SimpleLocalizeClient.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.simplelocalize.cli.client;
22

3+
import com.fasterxml.jackson.core.JsonProcessingException;
34
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.fasterxml.jackson.databind.SerializationFeature;
46
import com.jayway.jsonpath.DocumentContext;
57
import com.jayway.jsonpath.JsonPath;
68
import com.jayway.jsonpath.Option;
@@ -82,7 +84,15 @@ public String previewFile(UploadRequest uploadRequest) throws IOException, Inter
8284
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
8385
throwOnError(httpResponse);
8486
DocumentContext json = JsonPath.parse(httpResponse.body());
85-
return json.read("$.data").toString();
87+
return prettyPrintJson(json);
88+
}
89+
90+
private String prettyPrintJson(DocumentContext json) throws JsonProcessingException
91+
{
92+
Object data = json.read("$.data");
93+
ObjectMapper mapper = new ObjectMapper();
94+
mapper.enable(SerializationFeature.INDENT_OUTPUT);
95+
return mapper.writeValueAsString(data);
8696
}
8797

8898
public List<DownloadableFile> exportFiles(ExportRequest exportRequest) throws IOException, InterruptedException

0 commit comments

Comments
 (0)