s-yadav / jsonQ

A JavaScript library to make manipulation and extraction of data from a JSON very easy and fast.
MIT License
202 stars 69 forks source link

pathValue(...): Return 'undefined', instead of a run-time error, when path is not found #9

Open jayyuen1 opened 8 years ago

jayyuen1 commented 8 years ago

Hi s-yadav,

Thanks for writing jsonQ! I like the concept, and think this library is very helpful.

I noticed that, at least when running jsonQ in a node.js environment, I get a run-time error if I call the "pathValue" function when requesting a path that doesn't exist.

I made a small change so that undefined is returned instead.

For example,

const testObj = { apple: "fresh", vegetables: { carrot: "red", tomato: "orange" }}
console.log(jsonQ(testObj).pathValue(["colors", "blue"]))

Originally, jsonQ would throw an error in the second line. With the change I am proposing, jsonQ would return undefined instead.

What do you think?

Thanks, jayyuen1