From 0c81fa41914f4e23b59c6a66ef2b525bf8eb90ba Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 12 May 2018 15:14:41 +0200 Subject: [PATCH] cmd/syncthing: Return formatted JSON in API (#4945) Because machines don't care, and sometimes humans read the output. --- cmd/syncthing/gui.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 29fc35b9..6fb62d34 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -219,14 +219,14 @@ func sendJSON(w http.ResponseWriter, jsonObject interface{}) { w.Header().Set("Content-Type", "application/json; charset=utf-8") // Marshalling might fail, in which case we should return a 500 with the // actual error. - bs, err := json.Marshal(jsonObject) + bs, err := json.MarshalIndent(jsonObject, "", " ") if err != nil { // This Marshal() can't fail though. bs, _ = json.Marshal(map[string]string{"error": err.Error()}) http.Error(w, string(bs), http.StatusInternalServerError) return } - w.Write(bs) + fmt.Fprintf(w, "%s\n", bs) } func (s *apiService) Serve() {