0

This is more of a question in seeing if MySQL has any support for appending a JSON object without adding any extensions.

Say I have a JSON object that is in a person table in my MySQL server that contains the following:

    {"John":"male",
    "Jane":"female"}

and in any language that can execute MySQL code through their api wanted to add the following

    {"Jack":"male",
    "Jill":"female"}

to have the JSON object end up like this:

    {"John":"male",
    "Jane":"female",
    "Jack":"male",
    "Jill":"female"}

Would this be possible without grabbing the object and appending it within the code rather than executing a MySQL command. If it is possible, how would it be done?

I am currently using 10.3.22 of MariaDB.

0

1 Answer 1

1

Use the JSON_MERGE_PATCH() to combine JSON objects.

UPDATE person 
SET json_col = JSON_MERGE_PATCH(json_col, '{"Jack":"male", "Jill":"female"}')
WHERE ...
Sign up to request clarification or add additional context in comments.

1 Comment

(That function and JSON_MERGE_PRESERVE are available as of 5.7.22 and 10.2.25.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.