Refactored json generation.