gowebsocketgremlingraph-databasesjsonresult

go grammes - how to get property from gremlin, not just the value with go grammes


hello i'm using golang package "github.com/northwesternmutual/grammes" and want to get the field not just the value from response client so i can decode it to json

data, err := client.ExecuteQuery(g.V().Has("person", "name", "aksan").Values())
if err != nil {
    log.Fatalf("Querying error: %s", err.Error())
}
var responseStruct map[string]interface{}
err = json.Unmarshal(data[0], &responseStruct)
if err != nil {
    log.Fatalf("unmarshal error: %s", err.Error())
}
// Log out the response.
PrettyPrint(responseStruct["@value"], "result")

the response is

[
   {
      "@type": "g:Int64",
      "@value": 6
   },
   "p01",
   {
      "@type": "g:Int64",
      "@value": 10
   },
   "aksan",
   {
      "@type": "g:Int32",
      "@value": 29
   }
]

what i want is the result will showing field to like @fields or anything maybe something like this

[
   "height":{
      "@type": "g:Int64",
      "@value": 6
   },
   "code":"p01",
   "weight":{
      "@type": "g:Int64",
      "@value": 10
   },
   "name":"aksan",
   "age":{
      "@type": "g:Int32",
      "@value": 29
   }
]

Solution

  • Use ValueMap() instead of Values()