How to insert a list of JSONs into HBase using python

1.4k Views Asked by At

I have a list of JSON's which need to be read and inserted as JSON objects into HBase. Each JSON (could be a nested JSON) needs to be read from the list and inserted along with a new row key

put (key, <json>)

Format:

[ 
  {
    "x":"x-val",
    "y":222,
    "z":{
          "m":"m-val",
          "n":"n-val"
        }
  },
  {
     ..
  }
]
1

There are 1 best solutions below

0
On

You can use json.dumps(dict) to convert a dictionary to a JSON string.

json_data = [json.dumps(x) for x in list_of_data]

I recommend happybase to connect to HBase and store the JSON, as shown here. You can either loop over the json_data and do multiple puts, or explore happybase's batch functionality.