json-files-query
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

json-files-query

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.

Features

  • Execute queries on JSON files with specific conditions.
  • Perform searches using 'where' clauses.
  • Sort, skip, and limit results.

Installation

npm install json-files-query

Usage

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.

Examples of where clauses

// 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();

Package Sidebar

Install

npm i json-files-query

Weekly Downloads

2

Version

0.1.3

License

MIT

Unpacked Size

50.5 kB

Total Files

6

Last publish

Collaborators

  • yiwv