I have a large project where i am working with multiple developers where we are using react as our frontend with zustand as our state manager and python as our backend. What is the best practice for a frontend to process the json data given from the backend.
Example:
The backend sends
Data from api
{
something_a: "Some string",
something_b: "22-07-2020",
number_c: 60,
boolean_d: false
}
As of now, what i do is manually parsing each element into the zustand state which is an object. Something like this.
Parsing into variable/object/state manager
{
somethingA:datafromapi.something_a,
somethingB:datafromapi.something_b,
numberC:datafromapi.number_c,
booleanD:datafromapi.boolean_d
}
Reason behind this is so that if backend changes something_a
to somethingszs_a
or anything similar where the element has the same meaning, then i wouldn’t need to change every single file that uses something_a to somethings_a. Instead i just have to change it in the state manager only.
But if the backend ended up changing a something_a
into string_of_the_a
, same data, same use case but different name and probably even meaning, it would then cause confusion to other developers who read somethingA:data.string_of_the_a
A suggestion i got was to just parse data directly into the state manager and not have to manually retrieve the element like data:datafromapi
So the question is , what is the best practice to parse a json data into an object/variable/state manager?
This is considering it is a large project with many developers. Also, i understand that both is ok and works perfectly fine, but i am curious and also want to try to reduce some workload in the future for me and other developers.
Although i am using javascript/typrscript for this, i feel like this is not related to a specific programming language but more on naming convention and programming in general