Home Ask Login Register

Developers Planet

Your answer is one click away!

Altenrion February 2016

golang, revel, How to parse post json?

I'm rather new in golang, but I'm trying hard..

I'm trying to send json by post request to the revel controller, and parse it on the revel side.

But while getting the result I cannot Unmarshal it... I'm sending an array


But I can't find the correct way to work with such a data. I'm not sure do I need to make json before sending it or not..

func (c KpiCtrl) GetData() revel.Result {
    content, _ := ioutil.ReadAll(c.Request.Body)
    return c.RenderJson(content)



I tried to use json.Unmarshal but it returns errors.. What is the best practice to work with post data sent by curl to revel controller?


wlredeye February 2016

Just use standart json Decoder:

   var content []string
   err := json.NewDecoder(c.Request.Body).Decode(&content)
   if err != nil {
       log.Fatal("JSON decode error: ", err)
   defer c.Request.Body.Close()

Post Status

Asked in February 2016
Viewed 1,680 times
Voted 9
Answered 1 times


Leave an answer

Quote of the day: live life