jazzband / jsonmodels

jsonmodels is library to make it easier for you to deal with structures that are converted to, or read from JSON.
http://jsonmodels.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
334 stars 51 forks source link

How to load data from json file? #65

Open fportantier opened 8 years ago

fportantier commented 8 years ago

Hi !

I'm very impressed with jsonmodels, it's awesome!

I only don't know how I can save the data to json an, later, load it into the model, like this:

with open('data.json', 'r') as file: data = ujson.loads(file.read()) db = DB(load=data)

fportantier commented 8 years ago

Ok... my bad... searching on the internet:

with open('db.json', 'r') as file: data = ujson.loads(file.read()) db = DB(**data)

So simple!!! Sorry about the question,

only let me suggest that you put an example similar to the above on the docs, because it's very useful and I think that isn't present.

Regards and congrats for your awesome work!

beregond commented 8 years ago

Hi,

Nice to hear that, I'm glad it's useful for you :)

Anyway about reading json from file - well, json module is one great tool from python core - it's really well documented (https://docs.python.org/3/library/json.html) and, since it's core, I didn't want to put this into jsonmodels docs, since I wouldn't make it better than what's done already.

But in the end, I'll consider putting at least url to json docs. Thanks for feedback :)