JSON VS XML

There is another design question that always in the plate. Should we use json or xml as our data interchange pass through different system layers, APIs or system integration.

Let us talk about scenes to be used and different of these 2 most use of data format in the system data interchange.

1. Speed

JSON is obviously more lightweight. transfer/process speed is faster than XML. Especially in Browser/Server architecture application pass through different layers and APIs.

So generally use it will be used for data interchange in different layers.

For example, JSON Data in REST API and also frontend javascript component can pass JSON data to backends layers or APIs.

2. Readability

JSON is coming from Javascript. So if you use JSON as data storage, its readability will not be good as XML. Especially when your data model get more complicated and hierarchical elements present in your data model, JSON will not be a good fit.

XML has better readability as it is coming from the structural language definition.

3. Data Storage

In some cases, it will be better to storage data into files compare to store in DB.

If you want to store the lightweight configuration data, JSON should be a better choice.

In other cases. You should always choose XML as your preference.

For example, Some of the E-learning application and projects, According to SCORM standard, Most of study related content are stored in XML format e.g., Topic, Step etc. Then loaded into your learning applications.

4. Syntax strictness

XML data strictness is better than JSON. XML can define the schema, this will help you to validate your data model as very baseline feature.

XML can use parser to detect your XML data format if fit specification or not.

If JSON want do this, you need to write custom code or use other configuration do it.

In this case, XML is more used in the backends of the application to do data interchange compare to the frontend of the application

5. Application scenarios

XML seems more complicated than JSON as the way it presents in file.

But this is originally from its strictness. When your data model is complicated and also need some native validation. XML should be the better choice in this case. For example, DTD validation in XML.

Document data storage and the backends of the system configuration data storage are the most use case scenarios to use XML.

XML used in more wide range of backends open source framework as configuration data format.

For example, Spring Framework - applicationContext.xml

Mybatis - mapper.xml

Hibernate - hibernate.cfg.xml

Maven - pom.xml

You will see why these example that do not use JSON for a reason.

XML has another powerful feature. It is namespace. This is what JSON does not have.

JSON is more used in REST API data transfer with frontend javascript and also in some flat configuration data.

要查看或添加评论,请登录

Caihua Liu的更多文章

  • Java ORM Framework

    Java ORM Framework

    In recent days, I have been discussing with my friends what is the best suitable ORM(Object Relational Mapping)…

    1 条评论
  • SQL VS NOSQL Database

    SQL VS NOSQL Database

    There are always different opinions and choices what you want to choose for you database in your applications…

  • Agile - XP VS Scrum

    Agile - XP VS Scrum

    Development team want to choose Agile Development Methodology from either SCRUM or XP(Extreme Programming) Let us talk…

  • How the Empire of Spring Framework Derived

    How the Empire of Spring Framework Derived

    In recent days, I spoke some of my friends about SpringBoot. We did talk about the Spring IOC(Inversion of…

  • Clean Code-Be a good programmer

    Clean Code-Be a good programmer

    This is a very recommended book called Clean Code: A Handbook of Agile Software Craftsmanship. It is a mandatory book…

  • JDK 8 is the past, Now we have JDK 17

    JDK 8 is the past, Now we have JDK 17

    This was the discussion between me and my friends on which is the best JDK version we should use at the moment. Today…

  • The Dynasty iteration of Javascript Frameworks

    The Dynasty iteration of Javascript Frameworks

    What is the most popular Javascript framework in the javascript market. I want go through the original first iteration…

  • How to write code with OOP mindset

    How to write code with OOP mindset

    When we talk about the OOP Design, it is all about how to write your code with OOP mindset. This is very important if…

  • Which version of Spring Framework version we should go with

    Which version of Spring Framework version we should go with

    In recent days, I have been discussing with my friends on what is the best Spring Framework should be on in order to…

  • When to use(Git CLI vs GitHub vs Git IDE Plugin)

    When to use(Git CLI vs GitHub vs Git IDE Plugin)

    Git has replaced the SVN and CVS to be the most popular source code version control system in the market from several…

社区洞察

其他会员也浏览了