Created
November 24, 2021 14:30
-
-
Save cooliscool/3902f1affe5f703559b84e0ce34bdc1f to your computer and use it in GitHub Desktop.
Pretty print JSON from stdin - Go program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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