I need to get the main keys (devices) from a JSON formatted text with around 70.000 (sub-)keys/objects It looks like this:
{
"1":{...........}
"4":{...........}
"9":{...........}
}
And I need to get "1","4" and "9". But the way I do it now it takes around 2 minutes to parse the text with
json = json.loads(response.text) #this takes so long!
devices = json.keys()
because i'm running this on a Raspberry Pi!
Is there a better way?
EDIT: I recieve the data from a JSON API running on a server with:
http://.../ZWaveAPI/Run/devices #this is an array
EDIT3:
final working code: (runs for 2-5 seconds! :)
import ijson.backends.python as ijson
import urllib
parser = ijson.parse(urllib.urlopen("http://.../ZWaveAPI/Run/devices"))
list = []
for prefix,event,value in parser:
if event == "map_key" and len(prefix) == 0:
list.append(value)
return list