Parsing JSON in a request body with Go
✓ Published0🌍 Public
Aankuagar
Last edited Mar 11, 2014
Created on Mar 22, 2022
This example demonstrates a minimal HTTP server in Go that parses JSON from a request body and returns it as a response. The code reads the incoming request with `ioutil.ReadAll`, decodes it into a `Message` struct using `encoding/json`’s `json.Unmarshal`, then re-encodes the struct with `json.Marshal` before writing the result back with `w.Write`. The server uses the standard `net/http` package, registering a handler on the root path with `http.HandleFunc` and listening on port 8000 via `http.ListenAndServe`. It shows a round-trip JSON workflow without any external libraries or rendering.
AI-generated description