updated to support both json and xml.