CLI reference
Documents CLI command reference
Interact with documents in your project
npx sanity documents --help
pnpm dlx sanity documents --help
yarn dlx sanity documents --help
bunx sanity documents --help
Commands
create
USAGE
$ sanity documents create [FILE]
ARGUMENTS
[FILE] JSON file to create document(s) from
FLAGS
-p, --project-id=<PROJECT-ID> Project ID to create document(s) in (overrides CLI configuration)
-d, --dataset=<DATASET> Dataset to create document(s) in (overrides CLI configuration)
--id=<ID> Specify a document ID to use. Will fetch remote document ID and populate editor.
--json5 Use JSON5 file type to allow a "simplified" version of JSON
--missing On duplicate document IDs, don't modify the target document(s)
--replace On duplicate document IDs, replace existing document with specified document(s)
--watch Write the documents whenever the target file or buffer changes
DESCRIPTION
Create one or more documents
EXAMPLES
Create the document specified in "myDocument.json"
sanity documents create myDocument.json
Open configured $EDITOR and create the specified document(s)
sanity documents create
Fetch document with the ID "myDocId" and open configured $EDITOR with the current document content (if any). Replace document with the edited version when the editor closes
sanity documents create --id myDocId --replace
Open configured $EDITOR and replace the document with the given content on each save. Use JSON5 file extension and parser for simplified syntax.
sanity documents create --id myDocId --watch --replace --json5
Create documents in a specific project
sanity documents create myDocument.json --project-id abc123delete
USAGE
$ sanity documents delete ID [IDS]
ARGUMENTS
ID Document ID to delete
[IDS] Additional document IDs to delete
FLAGS
-p, --project-id=<PROJECT-ID> Project ID to delete from (overrides CLI configuration)
-d, --dataset=<DATASET> Dataset to delete from (overrides CLI configuration)
DESCRIPTION
Delete one or more documents from the projects configured dataset
EXAMPLES
Delete the document with the ID "myDocId"
sanity documents delete myDocId
ID wrapped in double or single quote works equally well
sanity documents delete 'myDocId'
Delete document with ID "someDocId" from dataset "blog"
sanity documents delete --dataset=blog someDocId
Delete the document with ID "doc1" and "doc2"
sanity documents delete doc1 doc2
Delete a document from a specific project
sanity documents delete myDocId --project-id abc123get
USAGE
$ sanity documents get DOCUMENTID
ARGUMENTS
DOCUMENTID Document ID to retrieve
FLAGS
-p, --project-id=<PROJECT-ID> Project ID to get document from (overrides CLI configuration)
-d, --dataset=<DATASET> Dataset to get document from (overrides CLI configuration)
--pretty Colorize JSON output
DESCRIPTION
Get and print a document by ID
EXAMPLES
Get the document with ID "myDocId"
sanity documents get myDocId
Get document with colorized JSON output
sanity documents get myDocId --pretty
Get document from a specific dataset
sanity documents get myDocId --dataset production
Get a document from a specific project
sanity documents get myDocId --project-id abc123query
USAGE
$ sanity documents query QUERY
ARGUMENTS
QUERY GROQ query to run against the dataset
FLAGS
-p, --project-id=<PROJECT-ID> Project ID to query (overrides CLI configuration)
-d, --dataset=<DATASET> Dataset to query (overrides CLI configuration)
--anonymous Send the query without any authorization token
--api-version=<API-VERSION> API version to use (defaults to 2025-08-15)
--pretty Colorize JSON output
DESCRIPTION
Query for documents
EXAMPLES
Fetch 5 documents of type "movie"
sanity documents query '*[_type == "movie"][0..4]'
Fetch title of the oldest movie in the dataset named "staging"
sanity documents query '*[_type == "movie"]|order(releaseDate asc)[0]{title}' --dataset staging
Use API version v2021-06-07 and do a query
sanity documents query '*[_id == "header"] { "headerText": pt::text(body) }' --api-version v2021-06-07
Query documents in a specific project and dataset
sanity documents query '*[_type == "post"]' --project-id abc123 --dataset productionvalidate
USAGE
$ sanity documents validate
FLAGS
-p, --project-id=<PROJECT-ID> Override the project ID used. By default, this is derived from the given workspace
-d, --dataset=<DATASET> Override the dataset used. By default, this is derived from the given workspace
--file=<FILE> Provide a path to either an .ndjson file or a tarball containing an .ndjson file
--format=<FORMAT> The output format used to print the found validation markers and report progress
--level=<LEVEL> The minimum level reported. Defaults to warning
--max-custom-validation-concurrency=<MAX-CUSTOM-VALIDATION-CONCURRENCY>Specify how many custom validators can run concurrently
--max-fetch-concurrency=<MAX-FETCH-CONCURRENCY>Specify how many `client.fetch` requests are allowed to run concurrently
--workspace=<WORKSPACE> The name of the workspace to use when downloading and validating all documents
-y, --yes Skips the first confirmation prompt
DESCRIPTION
Validate documents in a dataset against the studio schema
EXAMPLES
Validates all documents in a Sanity project with more than one workspace
sanity documents validate --workspace default
Override the dataset specified in the workspace
sanity documents validate --workspace default --dataset staging
Save the results of the report into a file
sanity documents validate --yes > report.txt
Report out info level validation markers too
sanity documents validate --level info
Validate documents in a specific project and dataset
sanity documents validate --project-id abc123 --dataset production