Languages
[Edit]
EN

MySQL - Insert JSON type value to the table

0 points
Created by:
Dirask Community
6390

In this article, we would like to show you how to insert JSON type value to the table in MySQL.

Quick solution:

INSERT INTO `table_name` (`column_name`)
VALUES
    ('{"key1": value1, "key2": value2, "key3": value3}'),
    ('{"key4": value4, "key5": value5, "keyN": valueN}');

 

Practical example

To show how to insert JSON type values to the table, we will use the objects table created in the previous article:

MySQL - example data used to insert JSON type values
MySQL - example data used to insert JSON type values

Example

In this example, we will insert into the objects table three new JSON values.

Query:

INSERT INTO `objects` (`json`)
VALUES
    ('{"height": 100, "width": 100, "color": "red"}'),
    ('{"height": 200, "width": 200, "color": "green"}'),
    ('{"height": 300, "width": 300, "color": "blue"}');

Result:

MySQL - INSERT INTO JSON type value - result
MySQL - INSERT INTO JSON type value - result

Related posts

MySQL - Problems

MySQL - Insert JSON type value to the table
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join