refactoring of JSON generator