Pyorient: how to parse json objects in pyorient?

1.2k views Asked by At

I have a value in orientdb, which is a JSON object. Assume that JSON object is :

a = {"abc":123}

When I am sending a query using pyorient, it is not able to get this value in the select query, and hangs. In the orientdb console, this JSON object seems to be converted in some other format like

a = {abc=123}

I guess it is hanging because of the same issue. The query from pyorient is:

client.query("select a from <tablename>")

This hangs and doesn't seems to be working. Could you please help ho to parse this JSON object in pyorient?

3

There are 3 answers

0
mayankchutani On BEST ANSWER

I used OrientDb's REST API service to fetch JSON object fields from the database. PyOrient hangs when requested for a JSON object field.

So fetch the rid of the record you want, and use REST services to get all the fields, which worked perfectly fine.

1
el3ctron On

pyorient gives you the output something like:

a = {'abc': '123'}

and json.loads() function works with " and not with ', so to solve it, you need to do this:

b=str(a)
b.replace("'",'"')
json_data = json.loads(b)
print(json_data.keys())
0
Rubanraj Ravichandran On

I have defined a function to get vertex and after you get your vertex you can use for loop to parse the json result. Lets say the vertex "Root" have an attribute "name", and in the for loop after the query execution we can parse the value like "res.name" to fetch the value.

I think in recent version, they fixed the hanging issue. I am not facing any issue with hanging while query execution.

def get_verted(vertex):
    result = client.command("select * from "+vertex)
    for res in result:
        print res.name
get_vertex("Root")