smarter json writing