MySQL 5.7: MySQL JSON operator example
This clip shows how to use MySQL json operator ->. To code this example I used workbench 6.3 and MySQL 5.7.
json operator is a short form of json_extract function.
It consist of three parts.
1) Column name on left hand side
2) Path on right hand side
3) In middle operator itself
example:
CREATE TABLE CodeVlog.json_test ( `id` int(11) NOT NULL, `friend` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
insert into CodeVlog.json_test(id,friend) values (1,'{"name":"Mac","marks":[10,40,100]}'), (2,'{"name":"Jack","marks":[60,80,200]}')
SELECT * FROM CodeVlog.json_test; SELECT friend->"$.name", friend->"$.marks[2]" FROM CodeVlog.json_test;
Check query output in video 🙂
Enjoy!!!
don’t forget to subscribe on YouTube as more code coming.