开发者

Deserialize django json data dump one record at the time?

I`m trying to read a file with json-data, use the loads(data) simplejson method and extract create a dictionary representing the values for each column in a record, instead of using the "standard" or documented way of :

for obj in serializers.deserialize("json", data):
    # do something with obj

because I want to avoid creating django orm objects for each record, I just want a dictionary representing each object so I can insert that into the database using plain SQL for gain speed. The problem is that loads(data) needs to read all th开发者_JAVA技巧e data into memory and I want to avoid that to keep memory usage low and read entry for entry in the json-data. Is it possible to get an iterator that yields data for one record? And secondly, can I skip the entire creation of django orm objects when deserializing the json data and just get a dictionary of the values?

Input and thoughts are welcome.

Thanks for your time.


If you don't want to create the ORM objects, there's no point in using the Django deserialization methods. Simply load the JSON using the underlying simplejson library:

from django.utils import simplejson
my_data = simplejson.loads(data)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜