4 ms·
I parse a lot of JSON in surprising and inconsistent formats and what works best for me is to immediately sanitize the object (option 1 that they describe) so t
by neetodavid 8y ago
I parse a lot of JSON in surprising and inconsistent formats and what works best for me is to immediately sanitize the object (option 1 that they describe) so that the rest of the code that operates on it can stay consistent
I'm interested in what an implementation of option 3 would look like. Is it just some regex to find the relevant characters in the string?
- base698 8y agoI think option 1 is a take on "be liberal with what you accept and conservative with what you send."
- klmr 8y agoNo, that’s orthogonal: Option 1 can mean either working around unexpected input, or failing in some way (and the same is true for the other options, but creating systematic, handle-able failures gets harder).
- MaulingMonkey 8y agoIf I'm lucky, for web stuff, I can just write a typescript interface definition or 5 to describe the JSON format, and suddenly I have working intellisense, protection from typos (after the first), etc.
- maxxxxx 8y agoThat doesn't protect you from inconsistent input. You still may have to sanitize.