I build a RESTful api with node.js and express / koa.
I want to filter the JSON data input - for security reasons as well to have only the needed business specific properties. After filtering the business-specific validation takes place.
How can I throw away unwanted JSON / JS object properties - i.e. properties not in my database schema as well as empty properties?
I think joi is a good library for validation and normalization. You can also sometimes get away with something as simple as _.pick from lodash/underscore.
You may consider using JSON-schema validators.
http://json-schema.org/implementations.html
Validators benchmark: https://github.com/ebdrup/json-schema-benchmark
Disclaimer: I created ajv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With