Refactor some helper code in JSON.Encode

(Now based on the parser-decoder-decoupling branch)

This makes it easier to define slightly more efficient helpers.

There is one slight semantics change: `{{"A", "B"}, {"C", "D"}}` won't get
encoded as `{"A": "B", "C", "D"}` but as `[["A", "B"], ["C", "D"]]` because a
tuple now gets treated as a non-keyword list instead of a possibly-keyword list.