Skip to content
Sanity
Get started
  • Sanity Studio - Flexible editing environment
  • Content Lake - Real-time database
  • Developer experience - Tooling you love
  • Structured content - The philosophy behind Sanity
  • Review changes - View edits & rollback instantly
  • Image pipeline - On-demand transformations
  • E-commerce - Better shopping experiences
  • Marketing sites - Control your story
  • Products & services - Innovate and automate
  • Mobile apps - Content backend for every OS
  • Aether - Unique digital shopping experience
  • Morning Brew - Omnichannel media distribution
  • InVision - Delivering exceptional customer experiences
  • DataStax - Personalization for global audience
  • React
  • Gatsby
  • Next
  • Nuxt
  • Eleventy
  • Netlify
  • Vercel
  • Algolia
  • Documentation
  • Reference
  • Guides
  • Resource library
  • Headless CMS
  • Tools & plugins
  • Project showcase
  • Schemas & snippets
  • Agency partners
  • Technology partners
  • Get support
  • Share your work
  • How I Learned to Expect More From My CMS
EnterprisePricing
Contact salesLog inGet started
Published November 27th 2020

Query your data inside VS Code

Get syntax highlighting and query execution for GROQ with the Sanity.io extension for VS Code.

Knut Melvær

Head of Developer Relations at Sanity.io

The Sanity.io extension for VS Code brings syntax highlighting and execution of GROQ queries. Super useful if you want to quickly see the data result of a query while your building, troubleshooting, or experimenting with code. The code execution feature was put together during the virtual all-hands hackathon that we had earlier this fall.

Try it out by installing the Sanity.io VS Code extension.

Using CodeLens (a feature that annotates code with useful contextual actions), you'll get an option to “Execute Query” whenever VS Code recognizes a GROQ query. You make it do so in a couple of different ways:

  • Put the query in a file with the .groq extension
  • Add fenced code blocks in Markdown with the groq tag
  • Use tagged template literals with the groq tag
  • Prefixed with the /* groq */ comment
  • Start a template literals with a // groq comment
// Markdown code block

```groq
*[_type == "post"]{title}
```

// Tagged template literal

import groq from 'groq'

const query = groq`*[_type == "post"]{title}`

// Prefixed template literal

const query = /* groq */`*[_type == "post"]{title}`

// Template literal starting with comment

const query = `//groq
  *[_type == "post"]{
    title,
    authors[]->{name}
  }
`

The extension also ships with configuration to turn off the CodeLens feature, and to whether to open query results in a new tab as an editable JSON file. If you use VS Code for your Sanity.io projects, you should also check out the Sanity snippet extension for quickly building out schemas.

Platform

Structured ContentDeveloper experienceContent LakeSanity StudioSecurity & Compliance
  • Sanity vs Contentful
  • Sanity vs Strapi
  • Sanity vs Adobe Experience Manager
  • Sanity vs Hygraph
  • Sanity vs Sitecore
  • Sanity vs Storyblok
  • Sanity vs Contentstack
  • Sanity vs Prismic
  • Sanity vs Drupal

Resources

Documentation
  • React Blog
  • Gatsby Blog
  • Next.js Landing Pages
  • Progressive Web Application
  • Single Page Application
  • Svelte & Typescript App
  • Vue & Tailwind Blog
  • Developer Portfolio Templates
  • Form validation with Yup
  • Live Preview with Next.js and Sanity.io
Resource library
  • Agency partners
  • Technology partners
  • Blog Template
  • Personal Website Template
  • Developer Portfolio Templates
  • All Templates
Case Studies
  • Headless CMS
  • What is an API CMS
  • Static Sites 101
  • Headless SEO
  • Localization
  • GraphQL vs REST
  • What is a DXP?
  • Typescript 101
  • React CMS
  • Next.JS CMS
  • CMS for Shopify
  • Content platform
  • Multilingual CMS
  • Static Site CMS
  • Gatsby CMS
  • Node CMS
  • E-commerce CMS
  • Vue CMS
  • Angular CMS
  • GraphQL CMS
  • Newspaper CMS
  • Magazine CMS
  • Mobile apps CMS

Company

Contact SalesEnterpriseCareersTerms of ServiceAccessibility Statement

Stay connected

  • GitHub
  • Slack
  • Twitter
  • YouTube
  • Stack Overflow
  • Blog RSS
  • Newsletter
©Sanity 2023