@@ -118,9 +118,6 @@ func init() {
118
118
if config .start != "" {
119
119
start = regexp .MustCompile (config .start )
120
120
}
121
- if config .readJSON && config .jsonTemplate == "" {
122
- config .jsonTemplate = "{{.}}"
123
- }
124
121
if config .jsonTemplate != "" {
125
122
config .readJSON = true
126
123
jsonTemplate = template .Must (template .New ("-jsontemplate" ).Option ("missingkey=zero" ).Parse (config .jsonTemplate ))
@@ -154,16 +151,18 @@ func main() {
154
151
line .I = i
155
152
match := line .Text
156
153
if config .readJSON {
157
- b .Reset ()
158
154
line .Object = new (interface {})
159
155
if err := json .Unmarshal ([]byte (line .Text ), & line .Object ); err != nil {
160
- fmt .Fprintln (os .Stderr , "parse error:" , err )
156
+ fmt .Fprintln (os .Stderr , "JSON parse error:" , err )
161
157
}
162
- if err := jsonTemplate .Execute (b , line .Object ); err != nil {
163
- fmt .Fprintln (os .Stderr , "template error:" , err )
158
+ if jsonTemplate != nil {
159
+ b .Reset ()
160
+ if err := jsonTemplate .Execute (b , line .Object ); err != nil {
161
+ fmt .Fprintln (os .Stderr , "template error:" , err )
162
+ }
163
+ line .JSONText = b .String ()
164
+ match = line .JSONText
164
165
}
165
- line .JSONText = b .String ()
166
- match = line .JSONText
167
166
}
168
167
if err := printer (& line ); err != nil {
169
168
fmt .Fprintln (os .Stderr , "output error:" , err )
0 commit comments