From bd6a8094d24eef88d4e0fdad16e805b660916e5a Mon Sep 17 00:00:00 2001 From: "Yingjie Chen (BEYONDSOFT CONSULTING INC)" Date: Mon, 28 Sep 2026 13:58:54 +0530 Subject: [PATCH] feat(deployment): indent JSON files written by FSWriter --- deployment/writer_fs.go | 1 + deployment/writer_fs_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/deployment/writer_fs.go b/deployment/writer_fs.go index 4d24269..c787141 100644 --- a/deployment/writer_fs.go +++ b/deployment/writer_fs.go @@ -346,6 +346,7 @@ func writeJSONFile(finalPath string, v any) error { enc := json.NewEncoder(tmp) enc.SetEscapeHTML(false) + enc.SetIndent("", " ") if err := enc.Encode(v); err != nil { // adds a trailing newline which is fine _ = tmp.Close() diff --git a/deployment/writer_fs_test.go b/deployment/writer_fs_test.go index 88ba95f..f546dcf 100644 --- a/deployment/writer_fs_test.go +++ b/deployment/writer_fs_test.go @@ -209,6 +209,42 @@ func TestWriteJSONFile(t *testing.T) { require.Equal(t, "y", dec["x"]) } +func Test_writeJSONFile_indented(t *testing.T) { + t.Parallel() + + path := filepath.Join(t.TempDir(), "obj.json") + obj := map[string]any{ + "name": "example", + "properties": map[string]any{ + "description": "Audit & report", + "metadata": map[string]any{}, + "nonComplianceMessages": []any{map[string]any{"message": "[[parameters('effect')]"}}, + "notScopes": []any{}, + }, + } + + require.NoError(t, writeJSONFile(path, obj)) + + b, err := os.ReadFile(path) + require.NoError(t, err) + + want := `{ + "name": "example", + "properties": { + "description": "Audit & report", + "metadata": {}, + "nonComplianceMessages": [ + { + "message": "[[parameters('effect')]" + } + ], + "notScopes": [] + } +} +` + require.Equal(t, want, string(b)) +} + func TestAddArmFunctionEscaping_MapSimple(t *testing.T) { t.Parallel()