Context: I am developing an application that consumes several APIs. The JSONs returned by these APIs have their own structure, which is often not the most intuitive for the programmer to exploit. / p>
Example: Suppose I am using an external API, and that this is JSON returned from any route.
{
"arvore": {
"avo": {
"pai": {
"eu": "pedro"
}
}
}
}
Suppose also that the only information that interests me in this JSON is the value of the key eu
. This way, every time I consume this resource and get this JSON, I will have to access my information of interest like this: obj['arvore']['avo']['pai']['eu']
or so obj.arvore.avo.pai.eu
, etc.
Problem / nuisance: Access to this information of interest is very verbose. And this may somewhat inhibit the speed of the development process in a larger scenario, anyway.
I was thinking of creating a sort of wrapper for the returned JSONs - of the resources I most use. For example, instead of accessing the key through its actual structure ( obj['arvore']['avo']['pai']['eu']
), I could simply give obj.eu
and then it would have exactly the same result. However, before implementing this, I wanted to raise this discussion here. Thank you very much.