Refactor json marshalling into own function

Considering replacing it, and this makes it easy to test and benchmark.
More JSON encoding speedups

Implement a custom encoder and bypass encoding/json completely.

benchmark               old ns/op     new ns/op     delta
BenchmarkJSON           144053        75409         -47.65%