There are some libraries to help with generic and unstructured json access https://awesome-go.com/json Check out FastJSON
#Grabbing certain information from response body
30 messages · Page 1 of 1 (latest)
thank u sm
@stone sundial could u help me figure it out cuz i got now clue how im gonnna get it working:P
I don’t have enough info, could you take a look at this blog post and ask a more complete question please? https://kesdev.com/how-to-ask-a-good-question/
um
Notably I need some code, what you’re trying to do, what happens, and what you want to happen
well
this is what the response looks like
{"status":"success","id":"myid","denormalized":{"myid":{"data":{"id":"name","my
name":"mario","gender":"m", "key":87374734}...
``` and blah blah
and i want to grab lets say
myname
or key
Nice, what code have you written to try to get that data out?
so first i tried to turn it into a struct
and that failed
so idk a different way
Try the instructions in fastjson
well i did
What code did you end up with?
if err != nil {
fmt.Println("No response from request")
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
return fastjson.GetString(body, "denormalized", "data")
Thanks. Let me try it out locally
kay
btw.. probably you should look at something like https://github.com/mitchellh/mapstructure
ill try this out thank u
It doesn't look like you followed the fastjson readme closely. You need to call Parse on the JSON raw data first
!go
var p fastjson.Parser
v, err := p.Parse(`{"status":"success","id":"myid","denormalized":{"myid":{"data":{"id":"name","my name":"mario","gender":"m", "key":87374734}}}}`)
if (err != nil) {
log.Fatal(err)
}
fmt.Println(string(v.GetStringBytes("denormalized", "myid", "data", "my name")))
The go bot doesn't seem to work here, but this will print out mario
ill try it out!
How dynamic is this json actually?
very