I have some JavaScript which does an ajax request from the server of which will return JSON data. Although this data is JSON, it is not correct as the script requires the data to be array-based and not contain objects.
A co-worker has suggested to use a client side solution to turn the object based JSON into array based JSON by recreating the JSON data.
I feel it should be more of a server side because I feel you should never rely on the clients browser to do such filtering? Isn’t it the servers job to do such data structure manipulation?
(By server side I mean – doing the exact same thing of which would be done on the client side but in PHP before the data is recieved from the AJAX request)
What is the best practice to do this and if possible explain the pros/cons of each side?
Thank you for your time.
Does the JSON from the server contain any sensitive data the user must not know about? When it does, you must filter it server-sided, because you can’t rely on the client to remove it.
Does the JSON contain information which is harmless, but merely unnecessary? Then it’s just a network performance thing. You need to evaluate for yourself if this optimization is worth your time.
But when the JSON does not contain any superfluous data and it is merely the representation which needs to be changed, then there is no reason why this shouldn’t be done client-sided.