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

groq-js

Package Overview
Dependencies
Maintainers
19
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

groq-js

GROQ-JS is a (work-in-progress) JavaScript implementation of [GROQ](https://www.sanity.io/docs/data-store/how-queries-work) which follows the official specification.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
170K
increased by9.18%
Maintainers
19
Weekly downloads
 
Created

What is groq-js?

The groq-js package is a JavaScript implementation of GROQ (Graph-Relational Object Queries), a query language designed for querying JSON documents. It allows you to perform complex queries on JSON data structures, making it particularly useful for applications that need to filter, sort, and transform JSON data.

What are groq-js's main functionalities?

Basic Querying

This feature allows you to perform basic queries on JSON data. In this example, the query fetches all objects of type 'person' from the data.

const groq = require('groq-js');
const data = { "name": "John", "age": 30 };
const query = '*[_type == "person"]';
const result = groq.evaluate(query, data);
console.log(result);

Filtering

This feature allows you to filter JSON data based on specific conditions. In this example, the query fetches all objects where the age is greater than 25.

const groq = require('groq-js');
const data = [
  { "name": "John", "age": 30 },
  { "name": "Jane", "age": 25 }
];
const query = '*[age > 25]';
const result = groq.evaluate(query, data);
console.log(result);

Projection

This feature allows you to project specific fields from JSON data. In this example, the query fetches only the 'name' and 'city' fields from the data.

const groq = require('groq-js');
const data = { "name": "John", "age": 30, "address": { "city": "New York" } };
const query = '{ name, address.city }';
const result = groq.evaluate(query, data);
console.log(result);

Sorting

This feature allows you to sort JSON data based on specific fields. In this example, the query sorts the objects by age in descending order.

const groq = require('groq-js');
const data = [
  { "name": "John", "age": 30 },
  { "name": "Jane", "age": 25 }
];
const query = '* | order(age desc)';
const result = groq.evaluate(query, data);
console.log(result);

Other packages similar to groq-js

FAQs

Package last updated on 20 Oct 2020

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