json refactoring

Refactoring only, no functional changes.