How to get the path matching with the dot path syntax ?
See original GitHub issueHi, I would like to know if it would be possible, when working with arrays, to get the path that matched with the condition.
const data = { a: [{ b: 1 }, { b: 2 }] };
const result = sift({ "a.b": 1 }, data);
// --> a[0].b
Would it be feasible with a custom operator or is there a place where I can grab that info ?
Thank you
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
JSONPath Syntax when dot in key - Stack Overflow
I get 'No match'. If I change the key to "footernavigationLinks" it works but I cannot control the key names in the JSON...
Read more >JSONPath Syntax | AlertSite Documentation
A JSONPath expression specifies a path to an element (or a set of elements) in a JSON structure. Paths can use the dot...
Read more >File path formats on Windows systems | Microsoft Learn
In this article, learn about file path formats on Windows systems, such as traditional DOS paths, DOS device paths, and universal naming ...
Read more >dot-path - npm search
Use property paths like 'a.b.c' to get a nested value from an object. Even works when keys have dots in them (no other...
Read more >Path Operations - Essential Java Classes - Oracle Help Center
You can easily create a Path object by using one of the following get methods from the Paths (note the plural) helper class:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Closing this for now since @stalniy seems to have a good fix.
Hi @J3m5
In terms of ucast, you need:
MongoQueryParser
- implemented in@ucast/mongo
JsInterpreter
- implemented in@ucast/js
If you want to learn more, start from here
This is not something I plan to add ucast at least for now, because its main goal is to translate conditions from language to another (e.g., mongo query -> SQL, query string -> Mongo query, etc)
Details: theoretically it’s possible to do. Currently,
@ucast/mongo
provides aMongoQueryParser
class, which you can use to parse any mongo query into AST (a tree of objects, you can think of it as something similar to XML tree). Having these objects, you can iterate over them to “interpret” them in anyway you need (e.g., XML can be interpreted as RSS, data transfer object or HTML).So, during iteration you can use operator interpreters from
@ucast/js
(e.g.,$lt
,$gt
, $in,
$eq`, etc) to get boolean result, also you need to aggregate path down the tree. As soon as operator returns true for your desired case, just stop iteration and return aggregated path.