0

I'd like to insert this JSON value ["Chien", "Chat"] in a JSON, with MySQL8 built-in JSON functions. So I tried with this query but I didn't get the expected output:

UPDATE tasks SET outputFields = JSON_SET(outputFields, '$.checkbox', '["Chien","Chat"]') WHERE id = 6832

This query made this valid JSON:

{"key1": "value1", "key2": "value2", "key3": "value3", "checkbox": "[\"Chien\",\"Chat\"]"}

The expected value is:

{"key1": "value1", "key2": "value2", "key3": "value3", "checkbox": ["Chien","Chat"]}

Is there a function or a work arround for it?

2
  • 1
    This is almost the same question as this one which I answered: stackoverflow.com/questions/69622166/… Commented Sep 30, 2022 at 14:34
  • It works with Cast function. Thank you Bill Commented Sep 30, 2022 at 15:30

1 Answer 1

2

Just use CAST function like this:

UPDATE tasks SET outputFields = JSON_SET(outputFields, '$.checkbox', cast('["Chien","Chat"]' as json)) WHERE id = 6832
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.