refactoring of JSON formatting logic
refactoring of JSON formatting logic