- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to store data in MySQL as JSON?
We can store data in MySQL as JSON with the help of JSON data type. The following is an example.
Let us now create a table.
mysql> CREATE table JsonAsMySQLDemo -> ( -> id int, -> name varchar(100), -> PageDemo JSON, -> eventInfo JSON -> ); Query OK, 0 rows affected (0.67 sec)
Storing records into JSON data type.
mysql> INSERT into JsonAsMySQLDemo values -> ( -> 1, -> 'John', -> '{"Page1":"/"}', -> '{"OperatingSystem":"Windows"}' -> ); Query OK, 1 row affected (0.24 sec) mysql> insert into JsonAsMySQLDemo values -> ( -> 2, -> 'Bob', -> '{"Page2":"/"}', -> '{"OperatingSystem":"Solaris"}' -> ); Query OK, 1 row affected (0.14 sec)
To display all records, use the SELECT
mysql> select *from JsonAsMySQLDemo;
The following is the output.
+------+------+----------------+--------------------------------+ | id | name | PageDemo | eventInfo | +------+------+----------------+--------------------------------+ | 1 | John | {"Page1": "/"} | {"OperatingSystem": "Windows"} | | 2 | Bob | {"Page2": "/"} | {"OperatingSystem": "Solaris"} | +------+------+----------------+--------------------------------+ 2 rows in set (0.00 sec)
- Related Articles
- How to store json values in object in android?
- Entering JSON data into MySQL?
- How to store JSON Object Singleton with Global Context in android?
- How do I format a number as decimal to store it in MySQL?
- How MySQL use YEAR data type to store year value in a table?
- How to store decimal in MySQL?
- How to group JSON data in JavaScript?
- How can I store ‘0000-00-00’ as a date in MySQL?
- How to store large data in JavaScript cookies?
- How to insert/store JSON array into a database using JDBC?
- What is the best data type to store money values in MySQL?
- The best data type to store 0, 1, null values in MySQL?
- How to query JSON datatype in MySQL?
- Which MySQL Data Type can be used to store Negative Number?
- How is it possible to store date such as February 30 in a MySQL date column?

Advertisements