small refactoring for to_json