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

groq-js

Package Overview
Dependencies
Maintainers
56
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

groq-js

[![npm stat](https://img.shields.io/npm/dm/groq-js.svg?style=flat-square)](https://npm-stat.com/charts.html?package=groq-js) [![npm version](https://img.shields.io/npm/v/groq-js.svg?style=flat-square)](https://www.npmjs.com/package/groq-js) [![gzip size][

  • 1.13.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
56
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

Keywords

FAQs

Package last updated on 26 Aug 2024

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