json: do not write to unexported fields

Fixes #977.
Fixes #451.

R=r, r2
CC=golang-dev
https://golang.org/cl/2246049
2 files changed