@@ -797,11 +797,11 @@ app.Get("/", func(c *fiber.Ctx) error {
797
797
Converts any **interface** or **string** to JSON using the [encoding/json](https://pkg.go.dev/encoding/json) package.
798
798
799
799
:::info
800
- JSON also sets the content header to **application/json**.
800
+ JSON also sets the content header to the ` ctype ` parameter. If no ` ctype ` is passed in, the header is set to **application/json**.
801
801
:::
802
802
803
803
` ` ` go title=" Signature"
804
- func (c *Ctx) JSON (data interface {}) error
804
+ func (c *Ctx) JSON (data interface {}, ctype ... string ) error
805
805
` ` `
806
806
807
807
` ` ` go title=" Example"
@@ -827,6 +827,22 @@ app.Get("/json", func(c *fiber.Ctx) error {
827
827
})
828
828
// => Content-Type: application/json
829
829
// => "{"name": "Grame", "age": 20}"
830
+
831
+ return c.JSON (fiber.Map {
832
+ " type" : " https://example.com/probs/out-of-credit" ,
833
+ " title" : " You do not have enough credit." ,
834
+ " status" : 403 ,
835
+ " detail" : " Your current balance is 30, but that costs 50." ,
836
+ " instance" : " /account/12345/msgs/abc" ,
837
+ }, " application/problem+json" )
838
+ // => Content-Type: application/problem+json
839
+ // => "{
840
+ // => "type": "https://example.com/probs/out-of-credit",
841
+ // => "title": "You do not have enough credit.",
842
+ // => "status": 403,
843
+ // => "detail": "Your current balance is 30, but that costs 50.",
844
+ // => "instance": "/account/12345/msgs/abc",
845
+ // => }"
830
846
})
831
847
` ` `
832
848
0 commit comments