INSERT INTO JSONDoc(Data) VALUES('{"AID": 1, "Name": "Harry Doe", "Email": "harry@earth.world", "CellPhone": "xxx0000xxx", "Address": "Earth, Milky Way Galaxy!", "RMX": "Fool"}'); -- Query OK, 1 row affected (0.01 sec) /* get content after insert operation of json doc */ SELECT * FROM JSONDoc WHERE DocID=1; -- +-------+------------------------------------------------------------------------------------------------------------------------------------------------+ -- | DocID | Data | -- +-------+------------------------------------------------------------------------------------------------------------------------------------------------+ -- | 1 | {"AID": 1, "RMX": "Fool", "Name": "Harry Doe", "Email": "harry@earth.world", "Address": "Earth, Milky Way Galaxy!", "CellPhone": "xxx0000xxx"} | -- +-------+------------------------------------------------------------------------------------------------------------------------------------------------+ -- 1 row in set (0.00 sec) /* remove RMX key from json doc using leading $ with the correct path*/ /* JSON_REMOVE: 1st arg - JSON DOC, 2nd arg - correct path to remove content! */ UPDATE JSONDoc SET Data = JSON_REMOVE(Data, '$.RMX') WHERE DocID=1; -- Query OK, 1 row affected (0.02 sec) -- Rows matched: 1 Changed: 1 Warnings: 0 /* get content after removing `RMX` key from the json doc */ SELECT * FROM JSONDoc WHERE DocID=1; -- +-------+---------------------------------------------------------------------------------------------------------------------------------+ -- | DocID | Data | -- +-------+---------------------------------------------------------------------------------------------------------------------------------+ -- | 1 | {"AID": 1, "Name": "Harry Doe", "Email": "harry@earth.world", "Address": "Earth, Milky Way Galaxy!", "CellPhone": "xxx0000xxx"} | -- +-------+---------------------------------------------------------------------------------------------------------------------------------+ -- 1 row in set (0.00 sec) /* update Name, Email in the json doc */ /* JSON_REPLACE expects first argument is the json doc to update and rest of the argument follows {path, value},... fashion. */ UPDATE JSONDoc SET Data = JSON_REPLACE(Data, '$.Name', 'John Doe', '$.Email', 'john@earth.world') WHERE DocID=1; -- Query OK, 1 row affected (0.02 sec) -- Rows matched: 1 Changed: 1 Warnings: 0 /* get content after updating Name, Email info in the json doc */ SELECT * FROM JSONDoc WHERE DocID=1; -- +-------+-------------------------------------------------------------------------------------------------------------------------------+ -- | DocID | Data | -- +-------+-------------------------------------------------------------------------------------------------------------------------------+ -- | 1 | {"AID": 1, "Name": "John Doe", "Email": "john@earth.world", "Address": "Earth, Milky Way Galaxy!", "CellPhone": "xxx0000xxx"} | -- +-------+-------------------------------------------------------------------------------------------------------------------------------+ -- 1 row in set (0.00 sec) /* get the extracted info from the json doc */ /* extract single item -- Name */ SELECT JSON_EXTRACT(Data, '$.Name') FROM JSONDoc WHERE DocID=1; -- +------------------------------+ -- | JSON_EXTRACT(Data, '$.Name') | -- +------------------------------+ -- | "John Doe" | -- +------------------------------+ -- 1 row in set (0.00 sec) /* get the extracted info from the json doc */ /* extract multiple item, returns in an array -- Name, Email */ SELECT JSON_EXTRACT(Data, '$.Name', '$.Email') FROM JSONDoc WHERE DocID=1; -- +-----------------------------------------+ -- | JSON_EXTRACT(Data, '$.Name', '$.Email') | -- +-----------------------------------------+ -- | ["John Doe", "john@earth.world"] | -- +-----------------------------------------+ -- 1 row in set (0.01 sec)