Interview Prep
Interview questions, roadmaps and practice sets
Tutorials
Free tutorials on 30+ topics
Blog
Career guides, skills and interview tips
Free PDFs
Notes, cheat sheets and question banks
Certificates
Free skill tests and course certificates
Tools & Whiteboard
Free tools you can use right in the browser
Practice Tests
Mock tests, MCQs and quick Q&A
Free LMS
Learn on the Uncodemy LMS
Choose the best training program according to your career.
Improve the performance of your business with our innovative Industrial Training Program.
Read More →
Our instructor-led training classes are designed to make you an expert.
Read More →
Real-life case studies are a great way to demonstrate your practical knowledge.
Read More →
Explore blogs, latest technologies and industry updates with practical examples.
Read More →Browse all available training programs and choose the right one for your career.
Read More →Know more about who we are and what we stand for.
Discover our mission to equip individuals with essential IT skills and industry expertise.
Read More →
Free tutorials, interview questions, tools and calculators to help you learn.
Explore →Learn, practice and plan your career — bilkul free.
Book a free video counselling session and pick the right course for you.
Read More →You can keep your blog's post list in one JSON file and let JavaScript build sections such as "Latest posts" or "Python tutorials" from it, so adding a post means editing data, not HTML.
This tutorial builds that in plain JavaScript: the JSON format, the fetch and render code, the exact output, and the SEO trade-off to know about.

On a small static blog, the home page often repeats the same post cards in several places: a "Latest" strip, a category block, a "Featured" box. Copying HTML by hand into each one is slow and easy to get wrong. A cleaner approach is to store each post once in a JSON file and generate the sections from it.
Keep two lists: the posts, and the sections you want to show. Each section says which category to include and how many posts to show. Save this as /data/posts.json:
{
"sections": [
{ "id": "latest", "title": "Latest posts", "filter": "all", "limit": 3 },
{ "id": "python", "title": "Python tutorials", "filter": "python", "limit": 2 }
],
"posts": [
{ "slug": "python-lists", "title": "Python Lists Explained",
"category": "python", "date": "2026-10-02", "excerpt": "Create, slice and sort lists." },
{ "slug": "css-grid", "title": "CSS Grid in 10 Minutes",
"category": "css", "date": "2026-10-20", "excerpt": "Two-dimensional layouts made simple." },
{ "slug": "python-dicts", "title": "Working with Python Dictionaries",
"category": "python", "date": "2026-11-01", "excerpt": "Keys, values and common methods." },
{ "slug": "js-fetch", "title": "Using fetch() in JavaScript",
"category": "javascript", "date": "2026-09-15", "excerpt": "Load data from an API." }
]
}
Dates use the ISO format YYYY-MM-DD on purpose: ISO dates sort correctly as plain strings, so you do not need to parse them.
<div id="blog-sections"></div>
<script src="/js/sections.js" defer></script>
The defer attribute downloads the script without blocking the page and runs it after the HTML is parsed. If you are unsure about the difference, see async vs defer in JavaScript.
async function loadSections() {
const root = document.getElementById("blog-sections");
root.textContent = "Loading posts...";
try {
const res = await fetch("/data/posts.json");
if (!res.ok) throw new Error("HTTP " + res.status);
const data = await res.json();
root.textContent = "";
// newest first; ISO date strings compare correctly
const sorted = [...data.posts].sort((a, b) => b.date.localeCompare(a.date));
for (const section of data.sections) {
const posts = sorted
.filter(p => section.filter === "all" || p.category === section.filter)
.slice(0, section.limit);
root.appendChild(renderSection(section, posts));
}
} catch (err) {
root.textContent = "Could not load posts. Please refresh the page.";
console.error(err);
}
}
function renderSection(section, posts) {
const wrap = document.createElement("section");
wrap.id = section.id;
const h2 = document.createElement("h2");
h2.textContent = section.title;
wrap.appendChild(h2);
const list = document.createElement("ul");
for (const p of posts) {
const li = document.createElement("li");
const a = document.createElement("a");
a.href = "/blog/" + encodeURIComponent(p.slug);
a.textContent = p.title;
const date = document.createElement("small");
date.textContent = " - " + p.date;
const excerpt = document.createElement("p");
excerpt.textContent = p.excerpt;
li.append(a, date, excerpt);
list.appendChild(li);
}
wrap.appendChild(list);
return wrap;
}
document.addEventListener("DOMContentLoaded", loadSections);
After sorting, the order is: Working with Python Dictionaries (1 Nov), CSS Grid in 10 Minutes (20 Oct), Python Lists Explained (2 Oct), Using fetch() in JavaScript (15 Sep). The two sections therefore render as:
Latest posts
Working with Python Dictionaries - 2026-11-01
CSS Grid in 10 Minutes - 2026-10-20
Python Lists Explained - 2026-10-02
Python tutorials
Working with Python Dictionaries - 2026-11-01
Python Lists Explained - 2026-10-02
To add a post, you add one object to posts. To add a new block, such as "CSS tips", you add one object to sections. No HTML changes are needed.
It is tempting to build each card with a template string and innerHTML. That works, but if any title or excerpt contains HTML (for example, a title like Using <script> tags, or data from an external CMS), the browser will interpret it as markup. That can break your layout or open a cross-site scripting hole. Setting textContent always treats the value as plain text. encodeURIComponent does the same job for the slug inside the URL.
If you prefer writing markup, use a <template> element in the HTML, clone it with template.content.cloneNode(true), and fill the clone's fields with textContent.
fetch() on file:// pages. Serve the folder with a local server, for example python -m http.server 8000, and open http://localhost:8000.posts.json. Add a version query, such as posts.json?v=20261116, when you publish changes.Google can render JavaScript, but rendering may happen later than the first crawl, and other search engines and link-preview bots may not run your script at all. For navigation blocks like "Latest posts" that is usually fine, because each post still has its own static page. For content that must be indexed, generate the HTML at build time instead: a small script (or a static site generator such as Eleventy, Hugo or Astro) can read the same posts.json and write plain HTML. You keep the single source of data and lose the dependency on client-side JavaScript.
Once sections work, you can add a "Load more" button or infinite scrolling, as shown in this infinite scroll blog layout tutorial. If you want to store user preferences such as a chosen category, look at the localStorage to-do list project. For background on how the browser talks to servers, read what APIs are and how they work in web apps, and keep your code readable with clean code practices in JavaScript.
Uncodemy's Full Stack Development course teaches JavaScript, APIs and front-end frameworks through projects like this one.