prettyPrintJSON returns indented JSON if body is valid JSON, otherwise returns body as-is. Unlike json.MarshalIndent, this preserves the original key order from the input, which makes the dumps easier to read and compare with the original requests.
(body []byte)
| 262 | // Unlike json.MarshalIndent, this preserves the original key order from the input, |
| 263 | // which makes the dumps easier to read and compare with the original requests. |
| 264 | func prettyPrintJSON(body []byte) []byte { |
| 265 | if len(body) == 0 { |
| 266 | return body |
| 267 | } |
| 268 | |
| 269 | result := body |
| 270 | if json.Valid(body) { |
| 271 | result = pretty.Pretty(body) |
| 272 | } |
| 273 | |
| 274 | return result |
| 275 | } |
no outgoing calls