- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 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