API testing – JSON data format and XML data format

API testing

As introduced in previous articles, the data format in the API usually uses two main types: JSON (JavaScript Object Notation) and XML (Extensible Markup Language). Today, I will talk more about each type of format.

Table of Contents


Nowadays, JSON data format is used a lot in Restful API. It is built from Javascript, which is widely used language, compatible with both front-end and back-end of both web app and web service. JSON is a simple format with two components: keys and values.

Key represents the properties of Object

Value represents the value of each Key

In the above example, keys are on the left, values ​​are on the right.

There are many cases, 1 Key will have a Value as a sequence of key + value. For example picture:


In JSON use { } and [ ] to mark data. XML is similar to HMTL, uses tags for markup and is called nodes.

Take the example above but write it in xml, it would look like this:

Data format in HTTP

Back to previous articles, the header has the function to save information that the user does not know, including a component that determines the format of the data: Content-Type

When the client sends the Content-Type in the request’s header, it is telling the server that the data in the request’s body is formatted that way. When the client wants to send JSON it will set the Content-Type as “application/json”.

When starting to receive the request, the server will check the first Content-Type and so it knows how to read the data in the body. Conversely, when the server sends back a response to the client, it also sends back a Content-Type to tell the client how to read the body of the response.

Sometimes the client can only read one type of format, for example, JSON but the server returns XML, the client will get an error. Therefore, another component in the header, Accept, will help the client deal with the problem by telling the server what type it can read. Example: Accept : “application/json” .

Based on 2 components Content-Type and Accept, client and server can understand and work correctly.

Thank you for reading.

To see more articles about API testing , please go this link

Leave a Reply

Your email address will not be published. Required fields are marked *

API testing

Test runner – API testing

Test runner – According to the previous post, you already know how to create simple tests for each API, but a project has too many APIs and too many different tasks, each task is a collection of several APIs how must be solved. Along with that is the management method that you think is applicable […]

API testing

How to test API

After reading “test API with Postman” series, you should be able to grasp the basic knowledge of the API and the functions Postman provides. But how to arrange tests and write Testcases for API still seems not very clear, so today I will write a post about how to test API properly. Reminder of knowledge […]

API testing

API testing – API documentation

Postman, in addition to providing an API testing tool, also helps us to make API documentation extremely professional and easy. This API document can be shared by both the team and the client. Usually, the API is usually written by Dev on google sheets, but at a certain stage of development, the dev will be […]