package main import ( "net/http" "github.com/gin-gonic/gin" ) func main() { router := gin.Default() router.GET("/users", func(c *gin.Context) { users := []string{"John", "Jane", "Bob"} c.IndentedJSON(http.StatusOK, gin.H{"users": users}) }) router.Run(":8080") }
package main import ( "net/http" "github.com/gin-gonic/gin" ) type Person struct { Name string `json:"name"` Age int `json:"age"` } func main() { router := gin.Default() router.GET("/person", func(c *gin.Context) { person := Person{Name: "John Doe", Age: 30} c.IndentedJSON(http.StatusOK, person) }) router.Run(":8080") }This example shows how to render JSON response with the "IndentedJSON" function for a custom struct type. It uses the "json" tag to specify the key names in the output. Overall, Context IndentedJSON package is used to format JSON response in an indented way using the gin-gonic/gin library for Go language.