json writing can probably be static methods