Tuesday, December 20, 2011

JSON format as data exchange format is more intuitive

Client/Server data exchange contains request and response. Good request/response can help us understand business more easily.
In Web Applications, JSON has become the most popular data exchange format. And JSON can express business more clearly.

Below list some bad and good request/response.

Requirement - get students, condition: sex = male and age = 20

Bad request/response (Not use JSON)
Request
sex=male&age=20

Response
id=1,name=A
id=2,name=B
id=3,name=C
id=4,name=4

Good request/response (Use JSON)
Request
{
"sex": "male",
"age": 20
}

Response
studentList: [
{
"id": 1,
"name": "A"
},
{
"id": 2,
"name": "B"
},
{
"id": 3,
"name": "C"
},
{
"id": 4,
"name": "D"
}
]

Conclusion: JSON format is more intuitive.

No comments:

Post a Comment