Skip to main content

q: automatically print []byte as a string

ID
4344ea7
date
2026-08-21 07:18:47+00:00
author
Alex Chan <alexc@tailscale.com>
parent
9a2e2ab
message
q: automatically print []byte as a string

This is pretty much always what I want, if I'm printing a JSON response
or similar.
changed files
1 file, 2 additions

Changed files

q.go (2632 → 2665)

diff --git a/q.go b/q.go
index 4164547..70a7ae9 100644
--- a/q.go
+++ b/q.go
@@ -85,6 +85,8 @@ func toString(value any, a ...any) string {
 			v = strings.ReplaceAll(v, "%t", "\x1b[39m%t\x1b[39m")
 			return fmt.Sprintf(v, a...)
 		}
+	case []byte:
+		return string(v)
 	case int, int8, int16, int32, int64,
 		uint, uint8, uint16, uint32, uint64,
 		float32, float64, bool: