Reputation: 922
I am fetching JSON data from the web and I am confuse on which is the best and faster way to store and retrieve JSON. Since I am not I am not handling complex queries. Is it advisable to store as flat file data.json
or it should be in the database?
BTW, I am using PHP.
Upvotes: 1
Views: 2864
Reputation: 2156
It depends on the size of the data and the frequency of access. Not sure about MySql, but Postgres of late has excellent json-processing capabilities, allowing you to query or even index directly into your json data. This is definitely the way to go if your documents are several kilobytes at most or have almost constant size to keep the storage engine happy.
For large objects it's better to stick to the filesystem, storing a brief of the document in the DB to allow fast operations on most important fields.
edit: since the data will be frequently replaced, it is best to avoid disk writes and use a fast though less-reliable RAM-only storage like Redis.
Upvotes: 1