use encode_json only on refs (allow sending strings)