{"id":458,"date":"2020-11-11T03:15:00","date_gmt":"2020-11-11T08:15:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=458"},"modified":"2021-01-01T00:19:34","modified_gmt":"2021-01-01T05:19:34","slug":"php-how-to-convert-xml-to-json","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/php-how-to-convert-xml-to-json\/","title":{"rendered":"PHP: How to convert XML to JSON"},"content":{"rendered":"\n<p>Converting XML to JSON is very easy in PHP. See the following code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$jsonfile =  fopen(\"file.json\", \"w\") or die (\"Cannot open JSON file for writing\");\n$xml = simplexml_load_file(\"file.xml\") or die (\"Cannot load xml file\");\nfwrite($jsonfile, json_encode($xml));\nfclose($jsonfile);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>line 1: open an empty file to write JSON <\/li><li>line 2: load xml file <\/li><li>line 3: convert xml to json using json_encode function and then write the json file <\/li><li>line 4: close the file<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Converting XML to JSON is very easy in PHP. See the following code. line 1: open an empty file to write JSON line 2: load xml file line 3: convert xml to json using json_encode function and then write the json file line 4: close the file<\/p>\n","protected":false},"author":1,"featured_media":490,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[77,108],"class_list":["post-458","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-json","tag-xml"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=458"}],"version-history":[{"count":2,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/458\/revisions"}],"predecessor-version":[{"id":491,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/458\/revisions\/491"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media\/490"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}