Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js /JavaScript - Java's Jackson equivalent

Is there a technique or module I can use in my node project that will take in JSON from a rest API and store it in some sort of readable object?

I understand currently that when I get data from a REST API, express's body parser will store it as a JSON object for me and I can traverse the tree from there, my issue is what if a contributor to my project has no idea what the JSON from the REST API looks like.

In Java you can tell since JACKSON will map it to a Java bean, in JavaScript I feel like you are going in blindly. If a contributor is using sublime and they don't have a debugger how should they figure out what the JSON object looks like?

like image 430
Michael Avatar asked Sep 11 '25 18:09

Michael


1 Answers

In nodejs, you can use express-jsonschema package to validate the incoming json to rest endpoints. If the json is not compliant with schema, you can respond with bad request error ( http status 400).

Please look more about this package on package manager (npmjs.com).

like image 129
notionquest Avatar answered Sep 13 '25 09:09

notionquest