Move json print methods into if statement