How to store Json file in DiscoDB

85 views
Skip to first unread message

shesha...@gmail.com

unread,
Oct 17, 2014, 1:13:17 AM10/17/14
to disc...@googlegroups.com
Hi 

I have json file::
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
{
       "employees":
         [
                { "Name":"John ssd" , "ID":"52" , "Department":"Graphics" },
                { "Name":"james Stone" , "ID":"45" , "Department":"Accounts"  },              
                { "Name":"fre rank" , "ID":"65" , "Department":"sales"  }
      ]
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I want's to load it into a DiscoDB

So I used this code 

file_json_data = open("json", "r")
lines = file_json_data.read().replace("\n", "").replace("\t", "").replace(" ", "")
tup = ast.literal_eval(lines)
db = DiscoDB(tup)

it's saying error as ""TypeError: must be string or read-only buffer, not dict"
 
is it stores json files?



Mark Duske

unread,
Mar 7, 2015, 1:39:08 AM3/7/15
to disc...@googlegroups.com, shesha...@gmail.com
Hi,

DiscoDB is not much different from HBase in the aspect that data is pretty much a bunch of bytes (but DISCODB actually understands values as arrays of bunches of bytes), the application is the one to serialize/deserialize the data, in this case what you want to accomplish can be done this way:

import ast

from discodb import DiscoDB

file_json_data = open("json.txt", "r")

#The trick is in making the array of values as a simple String
lines = file_json_data.read().replace("\n", "").replace("\t", "").replace(" ", "").replace("[","'[").replace("]","]'")


tup = ast.literal_eval(lines)
db = DiscoDB(tup)

#Read data from DISCODB
dictFromDiscoDB = ast.literal_eval(list(db['employees'])[0]);

#Print the unmarshalled data
for dictElement in dictFromDiscoDB:
        print dictElement['Department']

#Save DISCODB Results
db.dump(file('json.db', 'w'))
Reply all
Reply to author
Forward
0 new messages