Skip to content

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

Open
jayyuen1 wants to merge 1 commit into
s-yadav:masterfrom
jayyuen1:returnUndefinedWhenPathNotFound
Open

pathValue(...): Return 'undefined', instead of a run-time error, when path is not found#9
jayyuen1 wants to merge 1 commit into
s-yadav:masterfrom
jayyuen1:returnUndefinedWhenPathNotFound

Conversation

@jayyuen1

Copy link
Copy Markdown

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

…ction is called, and a non-existent path is passed in, then return 'undefined' instead of throwing an error. Prior to this commit, a runtime error would be thrown (at least when running within a node.js environment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant