Golang encoding/json.Compact() function example
package encoding/json
Compact appends to dst(1st parameter) the JSON-encoded src (2nd parameter) with insignificant space characters elided.
Golang encoding/json.Compact() function usage example
package main
import (
"bytes"
"encoding/json"
"fmt"
)
func main() {
dst := new(bytes.Buffer)
src := []byte(`{
"Name":"Adam Ng",
"Age":36,
"Job":"CEO"
}`)
err := json.Compact(dst, src)
if err != nil {
fmt.Println(err)
}
fmt.Println(dst)
}
Output :
{"Name":"Adam Ng","Age":36,"Job":"CEO"}
Reference :
Advertisement
Something interesting
Tutorials
+6.9k Android Studio : Hello World example
+14.6k Golang : Convert(cast) int to float example
+25.9k Golang : How to read integer value from standard input ?
+41k Golang : How to check if a string contains another sub-string?
+7.5k Golang : Detect sample rate, channels or latency with PortAudio
+6.7k Golang : Check if password length meet the requirement
+7.4k Golang : How to detect if a sentence ends with a punctuation?
+18.9k Golang : Read input from console line
+6.7k Golang : Skip or discard items of non-interest when iterating example
+9k Golang : Build and compile multiple source files
+47.8k Golang : Convert int to byte array([]byte)
+11.1k Golang : Fix go.exe is not compatible with the version of Windows you're running