json6
json6

Reputation: 85

Need help inserting json literal into mysql 5.7

When I try to insert the following query I keep getting this error message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '['php','javascript'])' at line 2

I am using the following query

INSERT INTO freelancer (tags) VALUES (['php','javascript']);

I tried another query, this time making it a string, and then I get this error

INSERT INTO freelancer (tags) VALUES ("['php','javascript']");

Invalid JSON text: "Invalid value." at position 1 in value for column 'freelancer.tags'.

I am not sure how to go about inserting this into mysql... if anyone can help me figure this out, I would really appreciate it!

Upvotes: 1

Views: 487

Answers (1)

tadman
tadman

Reputation: 211580

JSON is very particular about quotes. You must use doubles:

VALUES ('["php","javascript"]')

You can test with a JSON validator if you're curious about what is or isn't JSON.

Upvotes: 2

Related Questions