Skip to content
Go net/http handler to transparently manage posted JSON
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml Initial Commit Mar 19, 2015 Update Mar 20, 2015
example_test.go Initial Commit Mar 19, 2015
formjson.go Handle empty array as existing keys Dec 17, 2015
formjson_test.go Handle empty array as existing keys Dec 17, 2015

Go JSON handler godoc license build

FormJSON is a net/http handler implementing content negotiation for posted data in order to transparently expose posted JSON as if it was application/x-www-form-urlencoded. The posted data is then available using built-in r.FormValue("key")'s http.Request method.

To match capabilities of application/x-www-form-urlencoded, only single depth JSON object with string as keys and values is supported.


package main

import (


func main() {
    h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        body := fmt.Sprintf("Hello %s!", r.FormValue("name"))

    handler := formjson.Handler(h)
    http.ListenAndServe(":8080", handler)

Then this request:

curl -H "Content-Type:application/json" -d '{"name":"World"}' :8080

is now equivalent to this one:

curl -d name=World :8080


All source code is licensed under the MIT License.

You can’t perform that action at this time.