Use this tag for questions related to the use of the encoding/json package of Go language.
Questions tagged [encoding-json-go]
20 questions
0
votes
1 answer
How to compare all the child ID with their parent ID, In a deeply nested JSON?
This is the JSON document that i need to validate.
I have to check if all the parent_id in the Children are correct.
If all the parent and child Id is correct i will return a "valid" String.
{
"id": 10,
"children": [
{
"id": 25,
…

Lance
- 19
- 7
-1
votes
1 answer
Check if struct within struct exists
I have a json feed, and am trying to check if a struct within a struct exists.
type feed struct {
Video struct {
Name string `json:"name"`
}
}
And here's the unmarshal process:
data:= &feed{}
err :=…

clattenburg cake
- 1,096
- 3
- 19
- 40
-2
votes
2 answers
How to convert a time to UTC before marshaling as JSON in Go?
I'm trying to define a Time struct which implements the Marshaler interface such that, when it is marshaled to JSON, it is represented in the format YYYY-mm-ddTHH:MM:SSZ, that is, the time is converted to UTC and rounded to the nearest second. I've…

Kurt Peek
- 52,165
- 91
- 301
- 526
-2
votes
1 answer
hot to convert ioutil.ReadAll into json in golang
I'm trying to convert a response into json in golang.
func receive(w http.ResponseWriter, r *http.Request) {
reqBody, _ := ioutil.ReadAll(r.Body)
json.NewEncoder(w).Encode(string(reqBody))
println(string(reqBody))
func handleR() {
…

Fabian
- 11
- 3
-2
votes
2 answers
Parse a JSON with an empty string field
I need to parse a JSON into Go struct. Following is the struct
type Replacement struct {
Find string `json:"find"`
ReplaceWith string `json:"replaceWith"`
}
Following is an example json:
{
"find":"TestValue",
"replaceWith":""
}
The input…

tortuga
- 737
- 2
- 13
- 34