0.1.3 • Published 5 months ago

json-files-query v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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

5 months ago

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago