পদ্ধতি
MySQL-এ নেটিভ JSON সাপোর্ট (MySQL 5.7+) থাকা সত্ত্বেও, স্ট্রিং কনক্যাটেনেশন দিয়ে JSON-সদৃশ আউটপুট তৈরি করা যায়।
সারণি ও ডেটা
mysql> create table DemoTable1373 (StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentDetails text); mysql> insert into DemoTable1373 values(),(),(); -- ৩টি খালি সারি
আপডেট কোয়েরি
mysql> update DemoTable1373
-> set StudentDetails=concat("{", "StudentName:", " John ,", "StudentAge:", 21, ",", " StudentCountryName: ", "US", "}");
Query OK, 3 rows affected
ফলাফল
+-----------+---------------------------------------------------------------+
| StudentId | StudentDetails |
+-----------+---------------------------------------------------------------+
| 1 | {StudentName: John , StudentAge:21, StudentCountryName: US} |
| 2 | {StudentName: John , StudentAge:21, StudentCountryName: US} |
| 3 | {StudentName: John , StudentAge:21, StudentCountryName: US} |
+-----------+---------------------------------------------------------------+
উন্নত পদ্ধতি (MySQL 5.7+): JSON_OBJECT()
UPDATE DemoTable1373 SET StudentDetails = JSON_OBJECT( 'StudentName', 'John', 'StudentAge', 21, 'StudentCountryName', 'US' );
JSON_OBJECT() ভ্যালিড JSON তৈরি করে, যা JSON_EXTRACT(), -> অপারেটর দিয়ে কুয়েরি করা যায়।