Skip to content

yiwv/json-files-query

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published