Add a special case for `wait: true` in toJSON.

Ref #282, #338, #438