I am planning to store a json_encoded
string on my database. I can't precisely tell the length its going to be, but I'm pretty sure it will be long. My concern is which field type I am going to use for this, is it blob
or text
?
I prefer the one where I can save space as much as possible over fast searching, in any case I have other column where I should just index.
Note that any database will accept JSON documents as a single string blob. However, MySQL and PostgreSQL support validated JSON data in real key/value pairs rather than a basic string.
What are the differences between the BLOB and TEXT datatypes in MySQL? BLOB stands for Binary Large Objects and as its name suggests, it can be used for storing binary data while TEXT is used for storing large number of strings.
MySQL supports a native JSON data type defined by RFC 7159 that enables efficient access to data in JSON (JavaScript Object Notation) documents. The JSON data type provides these advantages over storing JSON-format strings in a string column: Automatic validation of JSON documents stored in JSON columns.
As stated in the documentation of MySQL, since 5.7.8 a native JSON data type is supported.
The JSON data type provides these advantages over storing JSON-format strings in a string column:
So, as the MySQL documentation states, the JSON data type should be used and not the text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With