Refactoring of write json to files