Widget property lock should compare json states, not python states

This makes the property lock for widgets store and compare the JSON state, since comparing python states can be crazy (for example, comparing two numpy arrays does not work in our `if a==b` test).

This PR includes #6331 to simplify the code for getting to/from_json functions.