Add json encoding from struct.

A first pass. There should be a better way to do this.