data-path-finder
v0.0.4
Published
Library and CLI tool to find properties of a JSON data structure using datapath string
Downloads
10
Readme
data-path-finder
This library allows for traversing a javascript object to find particular properties specified in a data-path string.
A data-path string provides the ability to specify an object-traversal mechanism to grab specific attribute values out of the provided object.
Data Path specification
A data-path string conforms to a simple specification of a property tree.
Consider the following javascript object:
{
userName:"Jose",
address: "San Pablo de Heredia",
favoriteCars: [
{
make:"Nissan",
model:"versa"
},
{
make:"Toyota",
model:"Rav4"
},
{
make:"Hyundai",
model:"Santa Fe"
}
]
}
The data-path specification "userName"
points to the value "Jose", while the data-path specification "favoriteCars[].make"
point to the value ["Nissan","Toyota","Hyundai"]
Uses of this library
Known uses for data-path expressions implemented in this library include data transformation, mapping and verification out of dynamic rules specified in text. For example for comparing two objects of different structure that may have common attributes.
Example using the cli.js file
- In an empty directory, run
npm install data-path-finder
- Then run
cd node_modules/data-path-finder/src
- Then run `node cli.js "../es_samples/favoriteCars.json" "favoriteCars[].make"
- The command should display a result of
["Nissan","Toyota","Hyundai"]