0

I have a column in my MySQL table that is type json. I am trying to update a row with a SQL script.

This is the JSON I am attempting to insert into the column

{
  "HE": [{
    "isbn": "1234",
    "type": "Some text"
  }],
  "HS": []
}

I have tried quite a few different ways with no luck, below is the method of updating a row I am most familiar with.

UPDATE `textbooks` 
SET `isbns` = {"HE":[{"isbn":"9781337763639","type":"Single Term HW & 
eBook University"}],"HS":[]} 
WHERE `id` = 939;

1 Answer 1

2

The JSON string has to be in quotes. Also, it shouldn't have newlines in it.

UPDATE `textbooks` 
SET `isbns` = '{"HE":[{"isbn":"9781337763639","type":"Single Term HW & eBook University"}],"HS":[]}'
WHERE `id` = 939;
Sign up to request clarification or add additional context in comments.

2 Comments

question in similar context, what if I would like to set isbn=id+something. In that case, how can I set any field in the json with variable params?
See the functions for modifying JSON values here

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.