Abraham Flores Cosme
Abraham Flores Cosme

Reputation: 31

When should I store JSON in a database?

I am working with a big database in MySql and I would like to know when is good to store data in JSON format instead of creating other tables.

Thanks.

Upvotes: 1

Views: 3334

Answers (2)

A1Gard
A1Gard

Reputation: 4168

Possible use cases for JSON format in a classic database:

  1. To avoid creating a table for unstructured data, enabling you to store data with any structure.
  2. To store data used directly by REST apps
  3. To avoid creating a table for data that does not need to be filtered or aggregated (e.g., SUM, MAX, etc.)
  4. For the added benefit of not having to write any JSON parsing code; the ORM or the language runtime takes care of it.
  5. When you need transfer load and parse from database to programming language same as PHP.

Upvotes: 2

Alp
Alp

Reputation: 3105

You can NOT search or index data expressed as JSON. It would be not very meaningful. It would be like a BLOB from DB's point of view.

So basically, you would just slap it into the database, and do not do anything with it? Then this begs the question whether you really need that JSON data at all?

If you are going to use bits and pieces of it more actively, then it makes sense to (at least those parts that you are interested in) get those parts out of JSON and put them in proper tables etc. That way you can search, index, relate these bits of data with others in a more meaningful way.

I hope it helps.

Upvotes: 0

Related Questions