Added JSON Function and integrated into main code.