Converting from and to JSON

The standard package json allows you to marshall and unmarshall to and from JSON data. Marshalling will return a byte array ([]byte). To pass it on or send it via web you will probably want to convert it to a string. Simply use a printf: str := fmt.Sprintf("%s", jsonData)

A simple example:

func (s *Server) AsJsonString() (str string, err os.Error) {
	asJson, err := s.Json()
	if err != nil {
		str = fmt.Sprintf("%s", asJson)
	}
	return str, err
}