Better way to serialize to a JSON