We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 91ca4ea commit dd0e726Copy full SHA for dd0e726
1 file changed
cmd/zon/main.go
@@ -1,6 +1,8 @@
1
package main
2
3
import (
4
+ "bufio"
5
+ "bytes"
6
"encoding/json"
7
"flag"
8
"fmt"
@@ -23,16 +25,29 @@ func run(r io.Reader, w io.Writer) error {
23
25
24
26
flag.Parse()
27
28
+ b := bufio.NewReader(r)
29
+
30
+ var dec Decoder = json.NewDecoder(b)
31
+ {
32
+ first, err := b.Peek(1)
33
+ if err != nil {
34
+ return err
35
+ }
36
37
+ if probablyZON := bytes.Equal([]byte("."), first); probablyZON {
38
+ dec = zon.NewDecoder(b)
39
40
41
42
if *j {
- dec := zon.NewDecoder(r)
43
enc := json.NewEncoder(w)
44
45
enc.SetIndent("", *i)
46
47
return convert(dec, enc)
48
}
49
- return convert(json.NewDecoder(r), zon.NewEncoder(w, zon.Indent(*i)))
50
+ return convert(dec, zon.NewEncoder(w, zon.Indent(*i)))
51
52
53
type Decoder interface{ Decode(v any) error }
0 commit comments