Skip to content

Commit 1f6e2e6

Browse files
author
Dean Karn
authored
Merge pull request #3 from go-playground/correct-json-output
Correct json output
2 parents 77bf1a9 + 0c49652 commit 1f6e2e6

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.1.0] - 2022-06-08
10+
### Fixed
11+
- CLI output to be JSON.
12+
913
## [0.1.0] - 2022-03-23
1014
### Added
1115
- Initial conversion from https://github.com/rust-playground/ksql.
1216

13-
[Unreleased]: https://github.com/go-playground/ksql/compare/v0.1.0...HEAD
14-
[0.1.0]: https://github.com/rust-playground/ksql/commit/v0.1.0
17+
[Unreleased]: https://github.com/go-playground/ksql/compare/v0.1.1...HEAD
18+
[0.1.1]: https://github.com/go-playground/ksql/compare/v0.1.0...v0.1.1
19+
[0.1.0]: https://github.com/go-playground/ksql/commit/v0.1.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ksql
22
=====
3-
![Project status](https://img.shields.io/badge/version-0.1.0-green.svg)
3+
![Project status](https://img.shields.io/badge/version-0.1.1-green.svg)
44
[![GoDoc](https://godoc.org/github.com/go-playground/ksql?status.svg)](https://pkg.go.dev/github.com/go-playground/ksql)
55
![License](https://img.shields.io/dub/l/vibe-d.svg)
66

cmd/ksql/main.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bufio"
5+
"encoding/json"
56
"fmt"
67
"os"
78

@@ -35,10 +36,20 @@ func main() {
3536
fmt.Fprintln(os.Stderr, "reading standard input:", err)
3637
return
3738
}
38-
if _, err = fmt.Fprintln(w, result); err != nil {
39+
b, err := json.Marshal(result)
40+
if err != nil {
41+
fmt.Fprintln(os.Stderr, "converting results to JSON:", err)
42+
return
43+
}
44+
if _, err = w.Write(b); err != nil {
45+
fmt.Fprintln(os.Stderr, "writing standard output:", err)
46+
return
47+
}
48+
if _, err = os.Stdout.Write([]byte{'\n'}); err != nil {
3949
fmt.Fprintln(os.Stderr, "writing standard output:", err)
4050
return
4151
}
52+
4253
}
4354
if err := scanner.Err(); err != nil {
4455
fmt.Fprintln(os.Stderr, "reading standard input:", err)
@@ -53,7 +64,19 @@ func main() {
5364
usage()
5465
return
5566
}
56-
fmt.Println(result)
67+
b, err := json.Marshal(result)
68+
if err != nil {
69+
fmt.Fprintln(os.Stderr, "converting results to JSON:", err)
70+
return
71+
}
72+
if _, err = os.Stdout.Write(b); err != nil {
73+
fmt.Fprintln(os.Stderr, "writing standard output:", err)
74+
return
75+
}
76+
if _, err = os.Stdout.Write([]byte{'\n'}); err != nil {
77+
fmt.Fprintln(os.Stderr, "writing standard output:", err)
78+
return
79+
}
5780
}
5881
}
5982

0 commit comments

Comments
 (0)