Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How dangerous is it to store JSON data in a database?

I need a mechanism for storing complex data structures created in client side javascript. I've been considering using the stringify method to convert the javascript object into a string, store it in the database and then pull it back out and use the reverse parse method to give me the javascript object back.

Is this just a bad idea or can it be done safely? If it can, what are some pitfalls I should be sure to avoid? Or should I just come up with my own method for accomplishing this?

like image 678
Spencer Ruport Avatar asked Mar 15 '11 08:03

Spencer Ruport


1 Answers

It can be done and I've done it. It's as safe as your database.

The only downside is it's practically impossible to use the stored data in queries. Down the track you may come to wish you'd stored the data as table fields to enable filtering and sorting etc.

Since the data is user created make sure you're using a safe method to insert the data to protect yourself from injection attacks (don't just blindly concatenate the data into a query string).

like image 104
SpliFF Avatar answered Sep 21 '22 18:09

SpliFF