Added saveToJSON function.