From: Operating system: Ubuntu Linux 10.04 PHP version: 5.3.6 Package: JSON related Bug Type: Bug Bug description:json_encode() doesn't convert SimpleXML data properly
Description: ------------ I tried to encode the following XML document in JSON using json_encode() and the result doesn't reflect the XML structure. XML document: <?xml version="1.0" encoding="UTF-8" ?> <a><b id="foo"/>bar</a> Result of json_encode(): {"b":{"@attributes":{"id":"foo"}}} The JSON results lost the "bar" value of the XML document. This is the source code that is used: <?php $xml='<?xml version="1.0" encoding="UTF-8" ?><a><b id="foo"/>bar</a>'; $simpleXML= simplexml_load_string($xml); echo json_encode($simpleXML); Test script: --------------- $xml='<?xml version="1.0" encoding="UTF-8" ?><a><b id="foo"/>bar</a>'; $simpleXML= simplexml_load_string($xml); echo json_encode($simpleXML); Expected result: ---------------- It's not obviuos the correct JSON rappresentation of the above XML document. In my opinion it can be as follow: {"a":[{"b":{"@attributes":{"id":"foo"}}},"bar"]} Where the value "bar" is included in a JSON array using the syntax [...] Actual result: -------------- {"b":{"@attributes":{"id":"foo"}}} -- Edit bug report at http://bugs.php.net/bug.php?id=54632&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54632&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54632&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54632&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=54632&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54632&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=54632&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=54632&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=54632&r=needscript Try newer version: http://bugs.php.net/fix.php?id=54632&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=54632&r=support Expected behavior: http://bugs.php.net/fix.php?id=54632&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=54632&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=54632&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=54632&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54632&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=54632&r=dst IIS Stability: http://bugs.php.net/fix.php?id=54632&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=54632&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=54632&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=54632&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=54632&r=mysqlcfg