Istvanb
Istvanb

Reputation: 412

Storing data in JSON or in SQLITE (Android)

I'm building an application which needs to retrieve data objects during runtime. Each one of the objects has the same structure (couple Strings, booleans and arrays). The size of a given object is relatively small (100-1000bytes). The user will not add/remove/modify elements during runtime so no write operation will be performed on the data. I expect that in the final version the number of object will be certainly below 5000. I will need to search for a given object or filter object based on criteria.

My question is if its sensible to use a JSON file? I love that JSON supports all my datatypes natively and can be edited very easily even from Android Studio. Once I put it to my assets folder it compiles with application seamlessly.

In the other hand SQLITE has the benefits of being a database, so searching, sorting etc would be easier than with a JSON file.

Upvotes: 0

Views: 134

Answers (2)

Ahmed.ess
Ahmed.ess

Reputation: 265

why not sharedpreferences and Gson, u can save your json as list of object and implement your search methods

in your case i think that using file is the best idea, the access time to a database is much greater than that for a file

Upvotes: 0

Gabe Sechan
Gabe Sechan

Reputation: 93559

There's nothing wrong with storing data in a json file. Its easily parsable, and a common means of storing small amounts of data, like settings. The disadvantages of it for storing large amounts of data is that it doesn't provide searchability, and getting access to be as efficient would require a lot of work.

You may want split the difference and look at a document based db. They basically store JSON, but still allow querying, handle caching, etc. This is assuming you have a significant amount of data, of course.

Upvotes: 1

Related Questions