Moved json logic from debug code