Implements writeJSON()