Simplify JSON serializer, add toJSON() test.