Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-query

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-query

Retrieves values from JSON objects for data binding. Offers params, nested queries, deep queries, custom reduce/filter functions and simple boolean logic. Browserify compatible.

  • 2.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
184K
decreased by-18.34%
Maintainers
1
Weekly downloads
 
Created

What is json-query?

The json-query npm package allows you to query and manipulate JSON data using a simple and intuitive syntax. It is particularly useful for extracting specific data from complex JSON structures.

What are json-query's main functionalities?

Basic Querying

This feature allows you to perform basic queries on JSON data. In this example, it filters the 'people' array to find entries where the 'country' is 'NZ'.

const jsonQuery = require('json-query');
const data = { people: [{ name: 'Matt', country: 'NZ' }, { name: 'Pete', country: 'AU' }] };
const result = jsonQuery('people[country=NZ]', { data: data }).value;
console.log(result); // Output: [{ name: 'Matt', country: 'NZ' }]

Nested Queries

This feature allows you to perform queries on nested JSON structures. In this example, it filters the 'people' array to find entries where the 'address.city' is 'Auckland'.

const jsonQuery = require('json-query');
const data = { people: [{ name: 'Matt', address: { city: 'Auckland' } }, { name: 'Pete', address: { city: 'Sydney' } }] };
const result = jsonQuery('people[address.city=Auckland]', { data: data }).value;
console.log(result); // Output: [{ name: 'Matt', address: { city: 'Auckland' } }]

Aggregation

This feature allows you to aggregate data from JSON structures. In this example, it extracts the 'age' values from the 'people' array.

const jsonQuery = require('json-query');
const data = { people: [{ name: 'Matt', age: 30 }, { name: 'Pete', age: 40 }] };
const result = jsonQuery('people.age', { data: data }).value;
console.log(result); // Output: [30, 40]

Complex Conditions

This feature allows you to use complex conditions in your queries. In this example, it filters the 'people' array to find entries where the 'age' is greater than 30.

const jsonQuery = require('json-query');
const data = { people: [{ name: 'Matt', age: 30 }, { name: 'Pete', age: 40 }] };
const result = jsonQuery('people[age>30]', { data: data }).value;
console.log(result); // Output: [{ name: 'Pete', age: 40 }]

Other packages similar to json-query

Keywords

FAQs

Package last updated on 05 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc