Skip to content

Instantly share code, notes, and snippets.

@gerep
Last active June 29, 2021 18:32
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerep/d1db8b2bbad9d3fe6f6cad25eda5259a to your computer and use it in GitHub Desktop.
Save gerep/d1db8b2bbad9d3fe6f6cad25eda5259a to your computer and use it in GitHub Desktop.
Compacting json data removing unused spaces: https://golang.org/pkg/encoding/json/#Compact
package main
import (
"bytes"
"encoding/json"
"fmt"
)
func main() {
data := `{ "spacedValue": "spaced value" }`
compactedBuffer := new(bytes.Buffer)
err := json.Compact(compactedBuffer, []byte(data))
if err != nil {
fmt.Println(err)
}
fmt.Printf("compacted buffer: %v", compactedBuffer)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment