Storing JSON as key value pair - mysql

My question is how to store a nested JSON as key value in mysql table. Earlier I thought of storing it as CSV but on deep diving I found it like it would be difficult to query those values and to manage as well.
Please help me in giving alternate solutions of how and where to store JSON.
The version of MySQL I am using does not support the JSON data type

If you are using MySQL 5.7, you can store ans query JSON objects. Look at this link for more details and examples.

Since MySQL 5.7 a native JSON data type is supported.
See also https://dev.mysql.com/doc/refman/5.7/en/json.html
If your MySQL version is lower the only option left is to store it as text. Otherwise you will not be able to store it in a simple key value pair manner.

Related

Can I use Laravel JSON Where Clauses with MariaDB 10.2.16 LongText column?

I tried to add a json column to my database by using phpMyAdmin
but Unfortunately, phpMyAdmin converts the json column to Longtext type
So, I'm asking about the ability to use the JSON Where Clauses with this type
https://laravel.com/docs/5.7/queries#json-where-clauses
You cannot use those queries on non-JSON data types in MariaDB. And as of 10.2, it doesn't officially support it.
You can use the JSON helper functions to query against data (ie: where JSON_CONTAINS(...) and others.
You can also create columns that are extracted values from the JSON data using Virtual Columns
Here's a good post with much more detail.

Decode json data while querying data from mysql database

Is it possible to retrieve decoded data from a mysql db column in which data is saved as json encoded text ie. instead of fetching json encoded text from the db and decoding it separately, is there any method to fetch decoded data from the select query itself?
Any help?
Thanks in advance!
The answer linked by jyoti mishra is quite good; MySQL handles JSON data internally now and json_extract is definitely the preferred solution if you're on MySQL 5.7 or later.
However, if you're not, you can use the phpMyAdmin "Transformation" feature to modify the displayed output when you're viewing through phpMyAdmin.
To start, you have to have at least partially configured the "phpMyAdmin configuration storage". From the table's Structure tab, "Change" the column containing the JSON data, then look for the "Browser display transformation" dropdown and select JSON. See this photo for an example:

How to save Array in database - Rails

I want to store array [3,9,21] in database (mySQL).Other than saving the values of array, I want to save the whole array in the database. Is it possible?
If you are using MySQL 5.7+ you can; it introduced a JSON data type https://dev.mysql.com/doc/refman/5.7/en/json.html
A quick read about the changes: http://lornajane.net/posts/2016/mysql-5-7-json-features
PS -- I'm a fan of the comment above -- storing values as separate rows instead of as arrays is a better option

What is the best way to store a pretty large JSON object in MySQL

I'm building a Laravel app the core features are driven with rather large JSON objects. (the largest ones are between 1000-1500 lines).
I know there are better data base choices than MySQL for storing files and blocks of data, but for various reasons I will need to use MySQL for the application.
So my question is, how to I store my JSON objects most effective in MySQL? I will not need to do any queries on the column that holds the data, there will be other columns for identifying it. Something like this:
id, title, created-at, updated-at, JSON-blobthingy
Any ideas?
You could use the JSON data type if you have MySQL version 5.7.8 or above.
You could store the JSON file on the server, and simply reference its location via MySQL.
You could use also one of the TEXT types.
The best answer i can give is to use MySQL 5.7. On this version the new column type JSON are supported. Which handles large JSON very well (obviously).
https://dev.mysql.com/doc/refman/5.7/en/json.html
You could compress the data before inserting it if you don't need it searchable. I'm using the 'zlib' library for that
Simply, you can use the type longblob which can handle up to 4GB of data for the column holding the large JSON object where you can insert, update, and read this column normally as if it is text or anything else!

Mysql, search in JSon field?

In my MySQL Database, some fields are "JSon text" fields.
Seoemtimes, I need to search/select from what these Json contain.
How should I do ?
Is there MySQL tools for achieving it ?
Thanks
http://labs.mysql.com/ refeers to MySQL JSon.
It is not fit for production yet.
Using a specific JSON type, rather than VARCHAR or TEXT, is definetely in progress by the MySQL Labs'.
It can be used with the latest MySQL releases, but seems quite beta.
Anyway, it's promising.
Googling a bit provides even documentation about it.
JSON type is to be a new type for MySQL.
it will make possible to search in Json-typed filed, and also to insert/delete/select, etc.