JSON
Converts any interface or string to JSON using Jsoniter.
JSON also sets the content header to application/json.
- c.JSON(v interface{}) error
- type SomeStruct struct {
- Name string
- Age uint8
- }
- app.Get("/json", func(c *fiber.Ctx) {
- // Create data struct:
- data := SomeStruct{
- Name: "Grame",
- Age: 20,
- }
- c.JSON(data)
- // => Content-Type: application/json
- // => "{"Name": "Grame", "Age": 20}"
- c.JSON(fiber.Map{
- "name": "Grame",
- "age": 20,
- })
- // => Content-Type: application/json
- // => "{"name": "Grame", "age": 20}"
- })