Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
JSON_MERGE_PATCH with null values (in Javascript)

As written in the docs, JSON_MERGE_PATCH will remove each value that is set to null, the following example will remove the header value from my settings json field

const data = JSON.stringify({header: null, otherdata: ...})
await connection.query(UPDATE shops SET JSON_MERGE_PATCH(settings, ?), data)

However what if I want to set the value to null, If I surround the header: 'null', with quotes, you can guess it: it enters 'null' as a string into my database.

Does anyone know if it's possible to have mysql update my json field with a null value?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As there doesn't seem to be a pure MySQL solution for this problem, you might be better off implementing this in JavaScript.

You'd implement this something like this:

  1. Fetch all records you want to modify some ID
  2. Use a solution like How can I merge properties of two JavaScript objects dynamically? to merge the objects
  3. Update all records with the new value

An alternate approach could be to use JSON_SET for each object key you have:

UPDATE shops SET JSON_SET(settings, '$.header', null)
-- Then repeat for each json key you want to modify
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!