import "github.com/gin-gonic/gin"
func Receive(c *gin.Context) {
// Gets JSON ecnoded data
rawData, err := c.GetRawData()
if err != nil {
return nil, err
}
logger.Info("Raw data received - ", rawData)
}
This code snippet works when I pass a Json object {"key":"value"} but gives an error:
"unexpected end of JSON input"
when I pass an array like [{"key":"val"},{"key": "val"}] as the input.
GetRawDatadoesn't do anything with json, it just reads the request's body, so that error that you quoted must come from code that you haven't shared.JSON (application/json)?GetRawDatacan't possibly return the errorunexpected end of JSON input(unless you're using some other version of gin), that error is returned byencoding/json's decoder, which is never touched byGetRawData. So the handler code you've shared is irrelevant to the problem you have, the error is coming from somewhere else. Whether its a problem with Postman, or gin attempting to do some magic, or some middleware you may be using, I don't know howeverGetRawDatait is not.