Skip to content

Instantly share code, notes, and snippets.

@cooliscool
Created November 24, 2021 14:30
Show Gist options
  • Save cooliscool/3902f1affe5f703559b84e0ce34bdc1f to your computer and use it in GitHub Desktop.
Save cooliscool/3902f1affe5f703559b84e0ce34bdc1f to your computer and use it in GitHub Desktop.
Pretty print JSON from stdin - Go program
package main
import ("fmt"
"encoding/json"
"os"
"bufio"
"bytes"
)
func main(){
var out bytes.Buffer
reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('\n')
err := json.Indent(&out, []byte(text), "", " ")
if err != nil {
fmt.Println(err)
}
fmt.Println(string(out.Bytes()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment