JavaScript - Querying Objects
07/10/2022, SunData Querying
As JSON/JavaScript objects are heavily relied upon means of accessing data, it is crucial to quickly retrieve certain pieces of information within the object quickly. For simple objects, a couple of loops will suffice in honing in to the exact detail, but most likely, the general object will be more complex.
A general querying library can alleviate the difficulty of getting a specific key or value within deeply nested objects. Ideally, the library of choice should have the following features:
- Operate on any JavaScript object.
- Avoid having to wrap your object around any special library object, or avoid the need to structure your object in a certain way.
- Provide dot notation access.
- Provide comparison functionality.
These are some evaluations for a select group of libraries that I have researched to fit the criteria defined above:
-
alasql Provides a really close SQL querying engine equivalent, but this library is too large for my liking.
-
jsonpath Operate on a single object at a time. This lacks the ability to perform comparisons between different objects.
-
nanosql Has SQL-Like querying capabilities. It even has observable querying support. Does not appear to be a maintained library.
-
mingo Provides Mongodb querying capabilities well suited for object access.
Ultimately, mingo was my choice for the query library because it offers a balance between size and functionality while also being maintained.