I have a question about json formatting. I have a requirement to produce the following json for a jquery plugin named DataTables...
{
"aaData": [{
"name": "Zane Music",
"address": "162 Castle Hill",
"town": "Berkshire"
}, {
"name": "Zander Exports",
"address": "34 Sapcote Trading Centre",
"town": "London"
}]
}
To try and achieve this I am using org.json.simple and have managed to produce the following...
{
"aaData": [{
"name": "Zane Music",
"address": "162 Castle Hill",
"town": "Berkshire"
}, {
"name": "Zander Exports",
"address": "34 Sapcote Trading Centre",
"town": "London"
}]
}
i.e. they are the same but the second listing is missing line breaks and is not properly formatted.
My question is does this matter for the consumer and is it good practice to have the json nicely formatted? Also is there a way to make it nicely formatted?
With json simple you specify the json by adding a method in the domain object like this...
public String toJSONString() {
JSONObject obj = new JSONObject();
obj.put("location", _location);
obj.put("locationName", _locationName);
obj.put("region", _region);
return obj.toString();
}
So I guess I could add line breaks where necessary.
Is that the right way to do it / is it necessary?
thanks