Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's better: Json or XML (PHP) [closed]

Tags:

json

php

xml

I'm manipulating few data with PHP, I have the choice between Json and XML. But I don't know what to choose, I never worked with one of them. So I want the easiest one.

Also I wonder if there's good classes that can make parsing (XML or Json) easier.

I focus mainly on ease of use rather than speed and scale.

like image 957
Omar Abid Avatar asked Jul 12 '09 20:07

Omar Abid


People also ask

Is XML ever better than JSON?

JSON is simpler than XML, but XML is more powerful. For common applications, JSON's terse semantics result in code that is easier to follow. For applications with complex requirements surrounding data interchange, such as in enterprise, the powerful features of XML can significantly reduce software risk.

When should I use XML over JSON?

In any case, if a project requires document markup and metadata information, it is better to use XML. Otherwise, for a more organized data interchange, JSON could be your preferred choice.

Why XML is more secure then JSON?

JSON does not provide namespace support while XML provides namespaces support. JSON has no display capabilities whereas XML offers the capability to display data. JSON is less secured whereas XML is more secure compared to JSON. JSON supports only UTF-8 encoding whereas XML supports various encoding formats.

Is XML still used 2021?

XML still lives today, mainly because it is platform agnostic. It supports Unicode and is often used as part of a data presentation workflow.


2 Answers

json.org makes JSON parsing simple. SimpleXML makes XML simple for PHP.

When choosing which one, it really depends on your application. If you will be passing data to JavaScript for processing on the client-side, then I recommend JSON. IMO, XML is better for data interchange between systems because it is very well understood and human readable (making interpreting easier for you). JSON is smaller over the wire, as there are no closing tags.

like image 63
geowa4 Avatar answered Sep 20 '22 22:09

geowa4


JSON parsing and generating is natively included in php: http://www.php.net/json

like image 33
Dykam Avatar answered Sep 19 '22 22:09

Dykam