SaveJSONFile saves data to a JSON file with proper formatting
(filePath string, data any)
| 27 | |
| 28 | // SaveJSONFile saves data to a JSON file with proper formatting |
| 29 | func SaveJSONFile(filePath string, data any) error { |
| 30 | dir := filepath.Dir(filePath) |
| 31 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 32 | return fmt.Errorf("failed to create directory: %w", err) |
| 33 | } |
| 34 | |
| 35 | jsonData, err := json.MarshalIndent(data, "", " ") |
| 36 | if err != nil { |
| 37 | return fmt.Errorf("failed to marshal JSON: %w", err) |
| 38 | } |
| 39 | |
| 40 | if err := os.WriteFile(filePath, jsonData, 0644); err != nil { |
| 41 | return fmt.Errorf("failed to write file: %w", err) |
| 42 | } |
| 43 | |
| 44 | return nil |
| 45 | } |
| 46 | |
| 47 | // GetFileNameWithoutExt returns filename without extension |
| 48 | func GetFileNameWithoutExt(filePath string) string { |
no outgoing calls
no test coverage detected