json-files-query
is a Node.js library that allows querying within a directory of JSON files, providing a straightforward way to retrieve data based on specific criteria. It is developed based on the queryContent
method of Nuxt Content.
- Execute queries on JSON files with specific conditions.
- Perform searches using 'where' clauses.
- Sort, skip, and limit results.
npm install json-files-query
Here's a quick example of how you can use json-files-query
:
import jsonFilesQuery from 'json-files-query';
const results = await jsonFilesQuery('/path/to/json/files')
.where({ title: 'Example' })
.limit(5)
.find();
console.log(results);
This code will search through the JSON files in the specified directory, filtering records with the title 'Example', and return up to 5 matches.
// numericField < 300
const results = await jsonFilesQuery('/path/to/json/files')
.where({ numericField: { $lt: 300 } })
.find();
// title matches the word "Word" (case-insensitive)
// (Using regex to ignore case)
const results = await jsonFilesQuery('/path/to/json/files')
.where({ title: { $regex: /Word/i } })
.find();