惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
J
Java Code Geeks
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
MongoDB | Blog
MongoDB | Blog
G
Google Developers Blog
Engineering at Meta
Engineering at Meta
量子位
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
A
About on SuperTechFans
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
Recent Announcements
Recent Announcements
腾讯CDC
I
InfoQ
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
爱范儿
爱范儿

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I built a free JSON formatter in a single HTML file (no l...
There's A We · 2026-04-29 · via DEV Community

Title:
I built a free JSON formatter in a single HTML file (no libraries, no backend)

Tags:
javascript webdev beginners opensource

Content:

I've used a lot of JSON formatters online. Most of them require an account, show aggressive ads, or send your data to a server. So I built one that does none of that — a single HTML file, no dependencies, runs entirely in the browser.
Here's what's inside it and how I built it.

The constraints I set for myself

One file only. No npm, no bundler, no framework.
Zero backend. Everything runs client-side.
No login, no tracking, no data leaves the browser.
Must work on any device without installing anything.

These constraints actually made it easier to build, not harder. When you remove the option of adding dependencies, you stop debating which library to use and just write the code.

Syntax highlighting without a library
This was the part I expected to be painful. It turned out to be a single regex replace:

javascriptfunction highlightJSON(str) {
  str = str
    .replace(/&/g, '&')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;');

  return str.replace(
    /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?|[{}\[\],:])/g,
    function(match) {
      let cls = 'j-num';
      if (/^"/.test(match)) {
        cls = /:$/.test(match) ? 'j-key' : 'j-str';
      } else if (/true|false/.test(match)) {
        cls = 'j-bool';
      } else if (/null/.test(match)) {
        cls = 'j-null';
      } else if (/[{}\[\],:]/.test(match)) {
        cls = 'j-punct';
      }
      return '<span class="' + cls + '">' + match + '</span>';
    }
  );
}

Enter fullscreen mode Exit fullscreen mode

It escapes HTML first to prevent XSS, then pattern-matches each token type and wraps it in a span with a CSS class. Keys, strings, numbers, booleans, nulls, and punctuation all get their own color. No library needed.

Live validation as you type
I didn't want to hammer the parser on every keystroke, so I debounced it with a 300ms delay:

javascriptlet liveTimer;
function liveValidate() {
  clearTimeout(liveTimer);
  liveTimer = setTimeout(() => {
    const raw = document.getElementById('input').value.trim();
    if (!raw) return;
    try {
      JSON.parse(raw);
      setInputStatus('valid', '✓ Valid JSON');
    } catch(e) {
      setInputStatus('invalid', '' + e.message);
    }
  }, 300);
}

Enter fullscreen mode Exit fullscreen mode

The status bar updates in real time — green dot for valid, red dot with the exact error message for invalid. JSON.parse throws a detailed error by default so you get the line number and description for free.

Deploying for free
The entire thing — hosting, SSL, CDN — costs nothing:

Code lives in a public GitHub repo
Deployed via GitHub Pages, which gives you a free yourusername.github.io URL instantly
SSL is handled automatically by GitHub, zero configuration needed

Go to repo → Settings → Pages → select main branch → save. It goes live in under 2 minutes. No account needed beyond a free GitHub account.

SEO for a tool like this
Since the tool targets developers searching things like "free json formatter no login", I added:

A descriptive

and with exact long-tail keywords<br> FAQ schema markup so Google can pull answers directly into search results<br> A sitemap.xml submitted to Google Search Console and Bing Webmaster Tools<br> Open Graph tags so the link looks clean when shared on Slack or Reddit <p>None of this required a plugin or a framework. It's all just a few tags in the </p>. <p>What I'd do differently<br> I'd add a shareable URL earlier — something like encoding the JSON in the URL hash so users can share a pre-loaded formatter link. It's a small feature but it gives people a reason to send the link to teammates, which is free distribution.</p> <p>The tool is live here: jameskonzern.github.io<br> If you're thinking of building a micro-tool, the single HTML file constraint is worth trying. It forces simplicity, deploys anywhere for free, and is surprisingly capable.</p>