Home > Article > Backend Development > Why use json instead of xml
Reasons: 1. The JSON structure is easier to map to the data structure of a general language; 2. XML needs to choose how to handle line breaks of element content, but JSON does not; 3. XML does not have a preset number format, but JSON does ;4. XML array element tags are relatively repetitive and redundant, while JSON is easier to read.
Why do many people oppose the use of XML and support the use of JSON? I will discuss this issue with you below.
Why use json? The reasons are as follows:
1. Due to usage factors, the structure of JSON is easier to map to the data structure of general language.
Let’s understand the main components of XML and JSON:
XML is element, attribute and element content.
JSON is object, array, string, number, boolean (true/false) and null.
2. XML needs to choose how to handle line breaks of element content, while JSON string does not need to make this choice.
3. XML only has text and no preset number format, while JSON has a clear number format, which is also safe in locale.
4. There is no big problem with XML mapping arrays, but the array element tags are relatively repetitive and redundant. JSON is easier to read.
5. JSON’s true/false/null can also be easily unified into the corresponding semantics of general programming languages.
The above is the detailed content of Why use json instead of xml. For more information, please follow other related articles on the PHP Chinese website!