handle parsing json automatically, move some encoding setup into main