When to prefer JSON over XML?

后端 未结 19 1588
无人共我
无人共我 2020-11-28 00:31

My requirement is just to display a set of values retrieved from database on a spread. I am using jquery.

19条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 01:08

    I am seeing a bit of bias dogma here. It appears that answers for this are over simplified for xml and coming from the context of Web Development only (which makes sense for the question), so I figured id offer some additional insight just in case some one crosses this and needs an answer for data serialization in other contexts.

    Here are the hard and fast rules:

    XML is definitely, not arguably, more powerful. So use it when your data model is complicated enough to need the following features:

    1. Support for Namespaces
    2. Support for Object Orientation ie inheritance/polymorphism
    3. Support for inclusion and extensibility for complex type reuse.
    4. Support needed for a reliable, mature and complete Schema Validation system.
      • the w3c Schema Validation system is vastly more capable to JSON Schema and has more literature to learn it.
    5. Support for mixed content document data modelling up AND record like data modelling.

    JSON is simpler to learn, understand and use. So use it when you dont have time to learn XML and dont have a need for any of the above features. Its also more lightweight on the wire, if that matters for your use case.

    TL:DR, XML can do everything json can do, but is heavier. The reverse is simply not true. Yes Json is simpler and therefor used more, but that does not mean it can supplant XML. In the case I was up against this year, 2020, json didnt make the cut for our use case, we literally needed XML. I can talk about that more if needed. Cheers and good luck.

提交回复
热议问题