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
+10.7k Golang : Change date format to yyyy-mm-dd
+13.1k Golang : How to check if your program is running in a terminal
+6.3k Golang : Of hash table and hash map
+20.2k Golang : GORM create record or insert new record into database example
+7.6k Golang : Count leading or ending zeros(any item of interest) example
+16.5k Golang : Login and logout a user after password verification and redirect example
+27.5k Golang : Detect (OS) Operating System
+11.5k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+7.7k Golang : Progress bar with ∎ character
+9.1k CodeIgniter : Load different view for mobile devices
+5.9k Golang : Muxing with Martini example