LooksLikeJSON checks if a string appears to be JSON by checking for opening and closing brackets/braces. It trims whitespace and returns false for empty strings.
(s string)
| 3791 | // LooksLikeJSON checks if a string appears to be JSON by checking for opening and closing brackets/braces. |
| 3792 | // It trims whitespace and returns false for empty strings. |
| 3793 | func LooksLikeJSON(s string) bool { |
| 3794 | s = strings.TrimSpace(s) |
| 3795 | if s == "" { |
| 3796 | return false |
| 3797 | } |
| 3798 | return (strings.HasPrefix(s, "{") && strings.Contains(s, "}")) || |
| 3799 | (strings.HasPrefix(s, "[") && strings.Contains(s, "]")) |
| 3800 | } |
| 3801 | |
| 3802 | // hasExplicitPort checks if the given host string (or host:port) |
| 3803 | // has an explicit port defined. It handles IPv6 addresses (e.g. [::1]:8080) correctly. |
no outgoing calls
no test coverage detected