Golang encoding/json.Indent() function example
package encoding/json
Indent appends to dst (1st parameter) an indented form of the JSON-encoded src (2nd parameter). Each element in a JSON object or array begins on a new, indented line beginning with prefix(3rd parameter) followed by one or more copies of indent(4th parameter) according to the indentation nesting. The data appended to dst does not begin with the prefix nor any indentation, and has no trailing newline, to make it easier to embed inside other formatted JSON data.
Golang encoding/json.Indent() 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"
}`)
json.Indent(dst, src, "**", "%%")
fmt.Println(dst)
}
Output :
{
**%%"Name": "Adam Ng",
**%%"Age": 36,
**%%"Job": "CEO"
**}
Reference :
Advertisement
Something interesting
Tutorials
+19.2k Golang : Check if directory exist and create if does not exist
+33.7k Golang : All update packages with go get command
+5.6k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+7.5k Golang : How to handle file size larger than available memory panic issue
+28k Golang : Move file to another directory
+6.9k Golang : How to setup a disk space used monitoring service with Telegram bot
+8.8k Golang : Get final balance from bit coin address example
+17.6k Golang : Parse date string and convert to dd-mm-yyyy format
+6.7k Golang : Experimental emojis or emoticons icons programming language
+19.6k Golang : Get current URL example
+36.5k Golang : Save image to PNG, JPEG or GIF format.