How to generate and reverse-engineer the schema.json File from a Production Deployment of the Studio?
Unfortunately, there's no straightforward way to download the original schema files from a deployed Sanity Studio. When you run sanity deploy, your schema files get bundled and minified into JavaScript - they're not stored separately on Sanity's servers in their original form.
However, there is a method to extract schema information from a deployed Studio, though it won't be perfect. A Sanity engineer created this gist that can help you recover schema definitions from the deployed bundle. The process involves:
- Opening your deployed Studio in a browser
- Using browser dev tools to access the bundled code
- Running extraction scripts to pull out schema information
Important caveats:
As mentioned in this community thread, the recovered schema will likely be "fractured" and may require significant cleanup. It won't perfectly match your original source code structure, and custom validation functions and other JavaScript logic may not be fully recoverable. It's really a last-resort option.
Why this happens:
When you deploy your Studio, the schema gets compiled into a JavaScript bundle that's served to browsers. Sanity doesn't receive or store your original schema files - only the compiled bundle. This is similar to how any web application works after being built and deployed.
Better approaches for the future:
- Use version control - Always commit your schema files to Git and push to a remote repository (GitHub, GitLab, etc.)
- Deploy via CI/CD - Set up GitHub Actions or similar to deploy from your repository, ensuring code is always backed up
- Schema deployment - While the newer
sanity schema deploycommand deploys your schema for platform features like Canvas and Agent Actions, it still doesn't store the original source files for recovery
For your current situation:
Try the gist method mentioned above, but be prepared to do manual cleanup and reconstruction. You might also want to check:
- If the original developer had any local backups or cloud storage
- Old deployment artifacts in CI/CD systems that might contain the source code
- Any archived emails or file shares where the code might have been sent
Going forward, treating your schema files as critical source code with proper version control will prevent this situation from happening again. This is a good reminder that while Sanity hosts your Studio, you're responsible for maintaining your source code.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.