Fix json generation

as_json is used by Rails and is expected to return a data structure, not a
JSON string. This is causing double-encoded errors when used in apps that
include ActiveSupport.

This change makes JSON generation match the pattern used by the JSON gem's
internal extensions.