Last active
June 29, 2021 18:32
-
-
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
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 ( | |
"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