mardi 28 mai 2019

JavaScript JSON API Parser w/ Default Values?

When consuming an external JSON API I expect certain values but I need to guard against bad inputs since I cannot control the external API.

Writing a local parser class is an option but seems pretty tedious. I need to check that the properties exist and that they are the right type (e.g. that the API did not return a string instead of an array or object) and this quickly adds up to a decent chunk of code.

Are there any standard ways of dealing with this? Any popular libraries? I tried a Google search but could not find anything.

Aucun commentaire:

Enregistrer un commentaire