How to update an element in json array with where clause?
You can use a query like the one below;

UPDATE table SET
  data = jsonb_set(data,'{pattern, values}', ((data-&gt;'pattern'-&gt;'values') - 'foo') ||  '["bar"]' )
WHERE
  (data #&gt; '{pattern, values}') ? 'foo';


Details; 

First you have to find records which have "foo" value in "values" array;

(data #&gt; '{pattern, values}') ? 'foo'


After that remove the value "foo" from the array;

((data-&gt;'pattern'-&gt;'values') - 'foo')


Create a new array by concatenating your new value(s).

((data-&gt;'pattern'-&gt;'values') - 'foo') ||  '["bar"]'


Replace new array with the old one.

jsonb_set(data,'{pattern, values}', new_array)