solve exercise 7: refactoring with "json" method