Start adding some Json encoding for State.

I used the ToJson instead of going via Encodable/Encoder because they're
just totally annoying to do anything nonstandard.