Added code to convert objects to JSON for output