|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45878 json_encode() bug report
Submitted: 2008-08-21 06:07 UTC Modified: 2008-08-21 20:49 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 2 (0.0%)
From: chenming522 at gmail dot com Assigned:
Status: Not a bug Package: JSON related
PHP Version: 5.2.6 OS: windows xp
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
47 + 5 = ?
Subscribe to this entry?

 [2008-08-21 06:07 UTC] chenming522 at gmail dot com
   I am a new gur for PHP program, Recently when I write a program that use php function json_encode() to translate a simpleXML object into json code, I found the attributes of the XML leafage node was lose.
   Wait to solve :).
Thank you.

Reproduce code:
	$xml_str = "<root><node attr='node attribute'>node value</node></root>";
	$xml_obj = simplexml_load_string($xml_str);
	$json = json_encode($xml_obj);
	echo $json;	// so where is node's attribute
	echo "\n=======================================\n";
	$xml_str = "<root><node attr='node attribute'></node></root>";
	$xml_obj = simplexml_load_string($xml_str);
	$json = json_encode($xml_obj);
	echo $json;	// found it, but why?

Expected result:
{"node":"node value"}
{"node":{"@attributes":{"attr":"node attribute"}}}

Actual result:
inlude node's value and attributes


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-21 20:49 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Sep 27 16:01:25 2023 UTC