📋JSON Templates
sitemap.json (JSON Sitemap)
JSON-based sitemap format (alternative to XML sitemap).
Explanation
JSON sitemaps are easier to generate and parse programmatically than XML.
Examples
Basic Sitemap
Output
{
"urls": [
{
"loc": "https://example.com/",
"lastmod": "2024-12-17",
"changefreq": "daily",
"priority": 1
},
{
"loc": "https://example.com/about",
"lastmod": "2024-12-15",
"changefreq": "monthly",
"priority": 0.8
},
{
"loc": "https://example.com/blog/post-1",
"lastmod": "2024-12-10",
"changefreq": "weekly",
"priority": 0.6
}
]
}Code Examples
TypeScript
interface SitemapEntry {
loc: string;
lastmod?: string;
changefreq?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
priority?: number; // 0.0 to 1.0
}
interface JSONSitemap {
urls: SitemapEntry[];
}
// Generate sitemap
function generateSitemap(pages: Array<{ url: string; updated: Date }>): JSONSitemap {
return {
urls: pages.map(page => ({
loc: `https://example.com${page.url}`,
lastmod: page.updated.toISOString().split('T')[0],
changefreq: 'weekly',
priority: page.url === '/' ? 1.0 : 0.8
}))
};
}Try it Now
💡 Tips
- Use XML sitemap for Google (better supported)
- JSON useful for internal tools
- Include lastmod for frequently updated pages
- Priority is relative within your site
- Split large sitemaps (50k URLs max)
⚠️ Common Pitfalls
- Google doesn't officially support JSON sitemaps
- Use XML sitemap.xml for SEO
- lastmod should be ISO 8601 date
- changefreq is just a hint