JSON cleanup and key handling