When to prefer JSON over XML ?

When to prefer JSON over XML ?

Asked on December 22, 2018 in XML.
Add Comment


  • 3 Answer(s)

    XML over JSON if any of these is true:

    • Need message validation
    • We using XSLT
    • Messages include a lot of marked-up text
    • We need to interoperate with environments that did not support JSON

    JSON over XML if all of these are true:

    • Messages no need to be validated, or validating their deserialization is simple
    • We are not transforming messages, or transforming their deserialization is simple
    • The messages are mostly data, not marked-up text
    • The messaging endpoints have good JSON tools
    Answered on December 22, 2018.
    Add Comment

    The alternate answer:

         Use JSON unless using XML. It is simpler to understand, because it requires less configuration and it is easier to program for reading and writing if the libraries are available in the context, and they are ubiquitous now.

    For instance,When Amazon first exposed their catalogs as a web service, they offered both JSON and XML. Something like 90% of the implementers chose JSON.

    Answered on December 22, 2018.
    Add Comment

    Preferring JSON over XML:

         Some specific case where users already doing javascript on the client side are considered, they can go with JSON for the reasons below,

    • JSON is native to javascript had to write less code on the client side – Just eval() or, better yet, JSON.parse() the JSON string and get an object that users can use.
    • At the same time evaluating JSON on the client-side will be more efficient and faster.
    • JSON serialization produces shorter strings than XML. Using JSON will reduce the amount of data running across the wire and improve performance in that respect.
    Answered on December 22, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.