I have been looking at JSONPath and though it seems pretty well done, I wonder if anyone has worked with it and can comment on its usability, or can recommend alternatives?
Try to using JSPath -- https://github.com/dfilatov/jspath.
JSPath is a domain-specific language (DSL) that enables you to navigate and find data within your JSON documents. Using JSPath, you can select items of JSON in order to retrieve the data they contain.
JSPath for JSON like an XPath for XML.
Not exactly what you are looking for, but check out object-scan. It is a bit more verbose, but is much more powerful and supports more (complex) use cases. Here is an example of how one could use it
const objectScan = require('object-scan');
const Characters = [{"id":"CuriousGeorge","species":"Monkey","mood":"curious","appendage":[{"type":"hand","side":"left","holding":[{"id":"Banana"}]},{"type":"hand","side":"right","holding":[]},{"type":"foot","side":"left","holding":[]},{"type":"foot","side":"right","holding":[{"id":"YellowHat"},{"id":"Keys"}]}]},{"id":"ManInYellowHat","species":"Human","mood":"angry"}];
console.log(objectScan(['**.holding.id'], {
useArraySelector: false,
abort: true,
rtn: 'parent',
filterFn: ({ value }) => value === 'Banana'
})(Characters));
// => { id: 'Banana' }
console.log(objectScan(['**.appendage[*]'], {
rtn: 'value',
filterFn: ({ value }) => value.type === 'hand' && value.side === 'left'
})(Characters));
// => [ { type: 'hand', side: 'left', holding: [ [Object] ] } ]
Make sure you check out the readme. It has a lot of examples in it.