开发者

What is larger: zipped json or zipped xml?

开发者 https://www.devze.com 2023-03-26 10:59 出处:网络
if I compare 2 data files containing the same data, but one of them the data is in XML format, the other one is JSON, and then both files are zipped (pkzip). How would they compare regarding the file

if I compare 2 data files containing the same data, but one of them the data is in XML format, the other one is JSON, and then both files are zipped (pkzip). How would they compare regarding the file size? My guess is that t开发者_JS百科hey probably have the same size, because zipping would take the more verbose element names of XML.

Just curious, thanks for your thoughts.


Simply put, zipped XML is larger, because it has same amount of information, plus the tags.


I think XML will be bigger because it contains start and end tags. For example:

Person:
    Name: Naor
    Address: none

Become in XML:

<Person>
    <Name>Naor</Name>
    <Address>none</Address>
</Person>

And in json:

Person: {Name:"Naor", Address:"none"} 


If you're representing mixed content then XML will probably be smaller, because JSON handles mixed content so inefficiently. But then, if you're interested in JSON then you're probably not interested in mixed content. In fact that's why for simple data XML is likely to be larger: the information content of a given message is higher (uses more bits) if it's expressed in a language where there's a larger permitted set of possible messages.


It would depend on the structure of the file and the compression algorithm, but in general JSON should be smaller in size. I just zipped two files (XML and JSON) with identical data using a standard windows tool, and JSON file had much better result (almost half the size of the original) compared to XML.

0

精彩评论

暂无评论...
验证码 换一张
取 消