I have a Go ReST service that receives JSON, and I need to edit the JSON so I may make two different structs.
My structs:
type Interaction struct{
DrugName string `json:"drugName"`
SeverityLevel string `json:"severityLevel"`
Summary string `json:"summary"`
}
type Drug struct {
Name string `json:"drugName"`
Dosages []string `json:"dosages"`
Interactions []Interaction `json:"interactions"`
}
Example JSON being sent:
{"drugName":"foo","dosages":["dos1"],"interactions":[["advil","high","summaryForAdvil"]]}
The ReST service:
func CreateDrug(w http.ResponseWriter, r *http.Request) {
//I verified the received JSON by printing out the bytes:
bytes, _ := ioutil.ReadAll(r.Body)
}
My goal is the make two different JSONs in the CreateDrug function so I may make the two different structs, Drug and Interaction:
{"drugName":"foo","dosages":["dos1"]}
{"drugName":"advil", "severityLevel":"high", "summary":"summaryForAdvil"}
In Go, in this function, how do I use the received JSON to make two new JSONs?