Salesforce REST returned in JSON not XML

When I am testing a Salesforce REST with Chrome, it was displayed in XML format. Therefore, I try to use SimpleXML with PHP to parse but never work. It is not SOAP and has nothing wrong with xmlsns (XML name space), neither.

XML displayed in Chrome with XML Tree installed
XML displayed in Chrome with XML Tree installed

I begin to wondering what my browser really get. First, I add a if statement to help me identify if the XML is load successfully after they get something from return:

$xml = simplexml_load_string($output);
if ($xml==false) $output = “False”; else $output=”Success!”;

The answer is “False”. I think there are something wrong with the returned value. But what’s the returned value? I remove XML related code and get something like this:


It is JSON! I was wrong. That’s why I never get what I want because I use a XML parser to interpret the returned string.

PHP has a json_decode which may parse JSON into arrray. I only need to use json_decode($output)->{‘fl_mobile__c’} or json_decode($output)->fl_mobile__c to access the fl_mobile__c field in return value.

Sometimes when I got nothing, it’s a good idea to check everything by dumping the value from beginning again.


  1. WordPress Plugin: preVU
  2. Calling Salesforce REST webservices without authentication
  3. Salesforce: workbench
  4. Salesforce: Dynamic SOQL
  5. Daniel Ballinger’s APEX String.format(); Syntax – escaping single quotes
  6. Tutorials2Learn: XML Parser using Javascript
  7. Stack Overflow: XML parsing of a variable string in JavaScript
  8. Tsung’s Blog: PHP 使用 SimpleXML 來解析 XML 內容、屬性
  9. Stack Overflow: How to convert array to SimpleXML
  10. PHP: SimpleXML
  11. PHP: simplexml_load_string
  12. sitepoint: SimpleXML and namespaces
  13. Salesforce: Interact with the REST API from PHP
  14. JSON: The Fat-Free Alternative to XML
  15. Stack Overflow: What is JSON and why would I use it?
  16. PHP: json_decode
  17. 小惡魔 – 電腦技術 – 工作筆記 – AppleBOY: 你不可不知的 JSON 基本介紹

One thought on “Salesforce REST returned in JSON not XML

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.