flushJSONToStdout writes JSON results to stdout when no output file is specified.
()
| 120 | |
| 121 | // flushJSONToStdout writes JSON results to stdout when no output file is specified. |
| 122 | func flushJSONToStdout() { |
| 123 | if (!jsonOutput && !jsonLines) || outputWriter != nil { |
| 124 | return |
| 125 | } |
| 126 | |
| 127 | jsonResultsMutex.Lock() |
| 128 | defer jsonResultsMutex.Unlock() |
| 129 | |
| 130 | if len(jsonResults) == 0 { |
| 131 | return |
| 132 | } |
| 133 | |
| 134 | if jsonLines { |
| 135 | for _, item := range jsonResults { |
| 136 | data, err := json.Marshal(item) |
| 137 | if err != nil { |
| 138 | fmt.Fprintf(os.Stderr, "[!] Error marshaling JSON: %v\n", err) |
| 139 | return |
| 140 | } |
| 141 | fmt.Println(string(data)) |
| 142 | } |
| 143 | return |
| 144 | } |
| 145 | data, err := json.MarshalIndent(jsonResults, "", " ") |
| 146 | if err != nil { |
| 147 | fmt.Fprintf(os.Stderr, "[!] Error marshaling JSON: %v\n", err) |
| 148 | return |
| 149 | } |
| 150 | fmt.Println(string(data)) |
| 151 | } |