JSON file VS SQLite android

23,989

Solution 1

Sqlite is mostly used when you want data to be saved and used in future. In your case data is changing every 5 minutes so its better to have JSON because every time to make the Database connection store and retrieve after 5 minutes will take some time.

UPDATE:

I also had the same Application in which the data was changing every time. In that case I used Map<K, V> and ArrayList to maintain the values, because as the data is changing everytime I think its not feasible to store the data in Sqlite everytime. It needs much time to perform DB Connection store, retrieve, update the data in Sqlite.

Solution 2

Advantages of SQLite:

  • Changes are ACID
  • You can make complex requests faster (e.g. "give me only fields A,B from items with (C/D)>E")
  • I would bet more compact for big data (integers are stored as integers instead of a string of individual digit)
  • Only one file
  • You can merge old data with new data easily
  • You can update current data, even while using it
  • Concurrency can be handled

Advantages for JSON/CSV:

  • Easier to debug (plain text)
  • Faster to make a whole update (copy the new file + delete the old one)

For the original question the whole delete/replace of the data makes JSON/CSV the winner.

However, if the application was to retrieve partial data every 10s and merge/update it with the previous one, SQLite would be a better option.

Solution 3

I recommend using JSON or some type of object serialisation unless:

  • You need ACID compliance for write operations
  • You need to report against the data which may involve copying the data to an external RDBMS or
  • You wish to join those complicit in the overuse / abuse of databases, as commonly seen nowadays
Share:
23,989
Rodrigo Amaro Reveco
Author by

Rodrigo Amaro Reveco

Updated on July 04, 2020

Comments

  • Rodrigo Amaro Reveco
    Rodrigo Amaro Reveco almost 4 years

    I will develop an android application with a lot of data (json files with some rows and CSV for graphics data with a lot of rows) , this data change every 5 minutes and replaces all the previous data (or mostly).

    What are the best approaches to design this ? I have 2 options:

    • Save all the data in a sqlite db, and sync this by a IntentService.

    • save the data in json and csv files and replace this every 5 minutes.

    Which approach will the best performance? This considering the time to parse the files, sorting data, the download time and the consistency of data.

    any other ideas?

    PD:I need a cache system too, in case if i don't have internet and I need the previous stored data

  • Rodrigo Amaro Reveco
    Rodrigo Amaro Reveco over 12 years
    I need a cache system too, in case if i don't have internet and i need the previous stored data
  • PravinCG
    PravinCG over 12 years
    that is fine do not overwrite/delete data unless you get the new data in correct format. This way your old data would continue to be in memory and being used.
  • SPB
    SPB over 11 years
    Hmmm....someone backed me up on this, presumably on the last point also. Perhaps I need to start a movement. Anyway, good old object serialisation is often the way to go.
  • Lou Morda
    Lou Morda over 9 years
    REST is used to send and receive data between server and client. JSON and SQLite both store data. But yes you can Post JSON data with RESTful methods faster.
  • Vahid Amiri
    Vahid Amiri over 8 years
    JSON is used for storing data as well.
  • apramc
    apramc almost 8 years
    Json is actually very commonly used for storing data, SQLite is better if the data can be broken to multiple separate tables with connection.
  • Nikolai Ehrhardt
    Nikolai Ehrhardt almost 3 years
    Its also possible to send sqlite db-files via http...
  • Zoe stands with Ukraine
    Zoe stands with Ukraine about 2 years
    "is used send and receive data between server and client" - it's also a popular storage format, but typically not database-grade storage. Yet, databases like MongoDB do in fact use JSON for database-grade data storage. The first point is blatantly wrong and an extreme oversimplification of JSON's role