refactored csv to json logic into a method

This script is a mess, so I'm moving each piece of logic into class methods.