How to load JSON / XML file into Gremlin console

1,705 views
Skip to first unread message

Aruna Shibane

unread,
Sep 3, 2015, 6:45:04 AM9/3/15
to Gremlin-users
Hi,
I have created a sample JSON and XML file and I am trying to load into Gremlin to perform basic operations. But it throws error says "File cannot be found". Please help.
esd_graph.json
esd_graph.xml

Wilfried Ehounou

unread,
Sep 3, 2015, 8:02:42 AM9/3/15
to Gremlin-users
you can do like that:
* for a json file
gremlin> g.loadGraphSon('path_To_your file/name_of_your_file.json')
* for a xml file 
gremlin> g.loadGraphML('path_To_your file/name_of_your_file.xml')

for example if your file 'esd_graph.json' is located at /home/pol/titan0_5 then 
g.loadGraphSon('/home/pol/titan0_5/esd_graphe.json.json')

i hope it will be useful 

Jason Plurad

unread,
Sep 3, 2015, 10:43:45 AM9/3/15
to Gremlin-users
Adding to Wilfried's reply, based on the format of your files, it looks like you are targeting TinkerPop2. If you are planning to use TinkerPop3, you'll need to get the formats updated.

I was able to load the GraphML file in the Gremlin shell like this:

gremlin> g = new TinkerGraph(); g.loadGraphML('/tmp/esd_graph.xml')
==>null
gremlin
> g.V()
==>v[1]
==>v[2]
==>v[3]
==>v[4]
==>v[5]
==>v[6]
gremlin
> g.E()
==>e[11][5-powers->4]
==>e[12][5-powers->6]
==>e[7][1-grounds->2]
==>e[8][1-grounds->3]
==>e[9][1-grounds->4]
==>e[10][1-grounds->6]


The GraphSON file posted previously had several errors in it. There were commas missing between objects in the vertices JSON array, and there were extra trailing commas in the edge objects. Also note the case on the loadGraphSON method. I've attached an updated file to this.

gremlin> g = new TinkerGraph(); g.loadGraphSON('/tmp/esd_graph.json')
==>null
gremlin
> g.V()
==>v[1]
==>v[2]
==>v[3]
==>v[4]
==>v[5]
==>v[6]
gremlin
> g.E()
==>e[11][5-knows->6]
==>e[12][5-knows->4]
==>e[7][1-knows->2]
==>e[8][1-knows->3]
==>e[9][1-knows->4]
==>e[10][1-knows->6]

esd_graph_fixed.json
Reply all
Reply to author
Forward
0 new messages