writes data to json