Split out JSON handling to separate file