Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to save JSON array to MySQL database?
For this, you can use JSON data type from MySQL. Let us first create a −
mysql> create table DemoTable1438 -> ( -> EmployeeDetails json -> ); Query OK, 0 rows affected (5.97 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1438 values('[{"EmployeeId":"EMP-101","EmployeeName":"Chris"},{"EmployeeId":"EMP-102","EmployeeName":"David"},{"EmployeeId":"EMP-103","EmployeeName":"Sam"}]');
Query OK, 1 row affected (0.22 sec)
Display all records from the table using select −
mysql> select * from DemoTable1438;
This will produce the following output −
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
| EmployeeDetails |
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
| [{"EmployeeId": "EMP-101", "EmployeeName": "Chris"}, {"EmployeeId": "EMP-102", "EmployeeName": "David"}, {"EmployeeId": "EMP-103", "EmployeeName": "Sam"}] |
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec) Advertisements
