An easy way to search for deeply nested data in large datasets
The below quickstart uses Node and TypeScript. If this quickstart does not fit your needs, check out the other guides below:
- Quickstart: Browser - JavaScript
- Quickstart: Node - JavaScript
- Quickstart: Deno - JavaScript
- Quickstart: Deno - TypeScript
-
Initialize your project as a Node project.
$ npm init -y
Note:
-y
skips all of the prompts. -
Install Accio and the
ts-node
CLI.$ npm install @drashland/accio $ npm install -g ts-node
-
Create your
data.json
file. You can copy theexample_data.json
file from this repository. -
Create your
app.ts
file.import { accio } from "@drashland/accio"; import { readFileSync } from "fs"; const data = readFileSync("./data.json", "utf-8"); const result = accio(data) .array("versions") // Target the array named "versions" .findOne({ // In the array, find one object that has a name field ... name: "v0.0.3", // ... with the value of "v0.0.3" }) .array("release_notes") // In the object, target the array named "release_notes" .findOne({ // In the array, find one object that has a title field ... title: "Bug Fixes", // ... with the value of "Bug Fixes" }) .array("body") // In the object, target the array named "body" .first(); // Target the first object in the array // Create the typing for the result type SomeType = { type: string; text: string; }; // Use the `.get()` call and pass in the typing to get a typed result const typedResult = result.get<SomeType>(); console.log(typedResult.type); console.log(typedResult.text);
-
Run your
app.ts
file.$ ts-node app.ts
You should see the following:
bullet Fix issue with date objects not being correctly validated.
View the full API documentation here.
Want to contribute? Follow the Contributing Guidelines here. All code is released under the MIT License.