0

I'm using this sample to make HTTP REST queries from Lambda.

The output format named as GraphSON

{
  "requestId": "104803b-e5d-4e49-bad8-e95e32fe7f0",
  "status": {
    "message": "",
    "code": 200,
    "attributes": {
      "@type": "g:Map",
      "@value": []
    }
  },
  "result": {
    "data": {
      "@type": "g:List",
      "@value": []
    },
    "meta": {
      "@type": "g:Map",
      "@value": []
    }
  }
}

and my general question how to specify serializer and get well-formatted JSON output instead of GraphSON without g:Map, @value, etc.

What I've tried: set particular values for Content-Type:

  • application/json
  • application/x-amz-json-1.1
  • application/vnd.gremlin-v3.0+json

Also I've tried to use values above as parameter for serializer in GET params, such as:

https://{host}:{port}/gremlin/?gremlin={query}&serializer=application/vnd.gremlin-v3.0+json

But returned data format still GraphSON.

Andrii Krupka
  • 4,276
  • 3
  • 20
  • 41

1 Answers1

1

You can fall back to GraphSON V2 which should yield well formed JSON. It will still have some of the type annotations but does not include map types. For example:

host='https://your-host-name.neptune.amazonaws.com'
curl -X POST $host:8182/gremlin\
     -d "{\"gremlin\":\"g.V('3').limit(1)\"}"\
     -H "Accept:application/vnd.gremlin-v2.0+json"\
     -H "Content-Type:application/vnd.gremlin-v2.0+json" | jq .

Which yields

{
  "requestId": "e053be96-73e7-4fc0-b02e-07bdf638cabc",
  "status": {
    "message": "",
    "code": 200,
    "attributes": {}
  },
  "result": {
    "data": [
      {
        "@type": "g:Vertex",
        "@value": {
          "id": "3",
          "label": "airport",
          "properties": {
            "country": [
              {
                "@type": "g:VertexProperty",
                "@value": {
                  "id": {
                    "@type": "g:Int32",
                    "@value": 1352763338
                  },
                  "value": "US",
                  "label": "country"
                }
              }
            ],
            "longest": [
              {
                "@type": "g:VertexProperty",
                "@value": {
                  "id": {
                    "@type": "g:Int32",
                    "@value": 134047490
                  },
                  "value": {
                    "@type": "g:Int32",
                    "@value": 12250
                  },
                  "label": "longest"
                }
              }
            ],
            "code": [
              {
                "@type": "g:VertexProperty",
                "@value": {
                  "id": {
                    "@type": "g:Int32",
                    "@value": -1353043840
                  },
                  "value": "AUS",
                  "label": "code"
                }
              }
            ],
            "city": [
              {
                "@type": "g:VertexProperty",
                "@value": {
                  "id": {
                    "@type": "g:Int32",
                    "@value": -342536989
                  },
                  "value": "Austin",
                  "label": "city"
                }
              }
            ],
            "elev": [
              {
                "@type": "g:VertexProperty",
                "@value": {
                  "id": {
                    "@type": "g:Int32",
                    "@value": -1300513844
                  },
                  "value": {
                    "@type": "g:Int32",
                    "@value": 542
                  },
                  "label": "elev"
                }
              }
            ],
            "icao": [
              {
                "@type": "g:VertexProperty",
                "@value": {
                  "id": {
                    "@type": "g:Int32",
                    "@value": -1123166874
                  },
                  "value": "KAUS",
                  "label": "icao"
                }
              }
            ],
            "lon": [
              {
                "@type": "g:VertexProperty",
                "@value": {
                  "id": {
                    "@type": "g:Int32",
                    "@value": -1327799778
                  },
                  "value": {
                    "@type": "g:Double",
                    "@value": -97.6698989868164
                  },
                  "label": "lon"
                }
              }
            ],
            "runways": [
              {
                "@type": "g:VertexProperty",
                "@value": {
                  "id": {
                    "@type": "g:Int32",
                    "@value": 200353151
                  },
                  "value": {
                    "@type": "g:Int32",
                    "@value": 2
                  },
                  "label": "runways"
                }
              }
            ],
            "region": [
              {
                "@type": "g:VertexProperty",
                "@value": {
                  "id": {
                    "@type": "g:Int32",
                    "@value": 1821242579
                  },
                  "value": "US-TX",
                  "label": "region"
                }
              }
            ],
            "type": [
              {
                "@type": "g:VertexProperty",
                "@value": {
                  "id": {
                    "@type": "g:Int32",
                    "@value": -1535682079
                  },
                  "value": "airport",
                  "label": "type"
                }
              }
            ],
            "lat": [
              {
                "@type": "g:VertexProperty",
                "@value": {
                  "id": {
                    "@type": "g:Int32",
                    "@value": -23584191
                  },
                  "value": {
                    "@type": "g:Double",
                    "@value": 30.1944999694824
                  },
                  "label": "lat"
                }
              }
            ],
            "desc": [
              {
                "@type": "g:VertexProperty",
                "@value": {
                  "id": {
                    "@type": "g:Int32",
                    "@value": -2074163175
                  },
                  "value": "Austin Bergstrom International Airport",
                  "label": "desc"
                }
              }
            ]
          }
        }
      }
    ],
    "meta": {}
  }
}
Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38