refactor JSON marshalling