Halfway through port to more robust Json handling