A JavaScript utility to safely retrieve nested values from objects using property paths like 'a.b.c', even when keys contain dots.
get-value is a JavaScript utility library that retrieves nested values from objects using property path strings like 'a.b.c'. It solves the problem of safely accessing deep properties, especially when keys contain special characters like dots, which many other libraries mishandle. It provides a reliable, performant alternative to native solutions and other dot-prop utilities.
JavaScript and Node.js developers who need to safely access nested object properties, particularly those working with configuration objects, API responses, or complex data structures where keys may include dots or other special characters.
Developers choose get-value because it correctly handles edge cases like dotted keys that break other libraries, offers excellent performance, and provides a flexible API with options for customization. Its reliability in real-world scenarios makes it a trusted choice for property access.
Use property paths (a.b.c) get a nested value from an object.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Unlike most libraries, it accurately accesses properties with dots in key names, as demonstrated in the README with examples like accessing 'a.b.c' when 'a.b' is a key.
Benchmarks show it's often faster than alternatives like dot-prop and object-path, especially for deep and root property access, making it suitable for performance-critical code.
Offers options for custom splitting, joining, and validation of paths, allowing adaptation to non-standard formats, such as using slashes or regex separators.
Seamlessly works with array indices (e.g., 'items.0.name') and function properties, enhancing its versatility in complex data structures.
Allows specifying fallback values when paths cannot be resolved, reducing boilerplate null checks and improving code reliability.
Only retrieves values; for setting or deleting nested properties, you must integrate separate libraries like set-value, adding complexity to dependency management.
The extensive customization options (e.g., split, join, isValid) can be overkill for basic dot notation access, potentially confusing developers with straightforward needs.
Since it uses string paths, it doesn't leverage TypeScript's compile-time type checking, which could lead to runtime errors if paths are mistyped or objects change structure.
Major versions like v3.0.0 and v4.0.0 introduced significant API changes, requiring code updates and careful migration planning for existing users.