Guide

JSON, Base64, URL encoding and HTML entities explained

What JSON, Base64, percent-encoding, HTML entities, UUIDs and Unix timestamps are for — and the common mistakes developers make with each.

How we made this: Technical explainer based on the relevant public standards (RFC 8259 for JSON, RFC 4648 for Base64, RFC 3986 for URIs, RFC 9562 for UUIDs) and the HTML specification. Editorial policy.

Most “it doesn’t work” bugs between systems come down to text formats: a missing comma in JSON, a space that wasn’t URL-encoded, a timestamp in the wrong unit. Here’s a quick, practical tour.

JSON

JSON (RFC 8259) is the default format for APIs and configuration. Its rules are strict:

  • Keys and strings use double quotes — never single quotes.
  • No trailing commas and no comments.
  • Numbers can’t have leading zeros; NaN, Infinity and undefined aren’t allowed.
  • Object keys should be unique. Most parsers silently keep the last duplicate, which hides bugs.

Use the JSON validator to find errors by line and column (including duplicate keys), and the JSON formatter to pretty-print or minify.

Base64

Base64 (RFC 4648) represents binary data using 64 safe text characters, so it can travel inside JSON, email or a data: URI. Every 3 bytes become 4 characters, making data about 33% larger. The URL-safe variant swaps +/ for -_ and often drops = padding — you’ll see it in JWTs.

A common bug: encoding text with btoa() in JavaScript fails on non-ASCII characters such as “é” or emoji. Convert to UTF-8 bytes first. The Base64 encoder does this correctly, and the Base64 decoder reverses it.

URL (percent) encoding

URLs can only contain certain characters (RFC 3986). Others are written as % plus two hex digits per UTF-8 byte: a space is %20, é is %C3%A9.

  • Encode each value you put into a query string with encodeURIComponent — it also escapes &, = and /.
  • Use encodeURI only to tidy a complete URL while keeping its structure.
  • HTML forms encode spaces as + in query strings.

Try both with the URL encoder, and unpick encoded links with the URL decoder.

HTML entities

When text is placed inside HTML, < and & (and quotes in attributes) must be written as entities — &lt;, &amp;, &quot; — or the browser treats them as markup. This is a key defence against cross-site scripting, though context matters (URLs and scripts need different handling). See the HTML entity encoder and HTML entity decoder.

UUIDs

UUIDs are 128-bit identifiers written as 36 characters. v4 is fully random; v7 (RFC 9562) starts with a timestamp, so new IDs sort in creation order — friendlier for database indexes. Generate either with the UUID generator.

Unix timestamps

A Unix timestamp counts seconds since 1 January 1970 UTC. JavaScript uses milliseconds, so 1767225600 (seconds) and 1767225600000 (ms) are the same moment. Store times in UTC and convert for display — South Africa is UTC+2 all year. Check values with the Unix timestamp converter.

Regular expressions

When you need to validate or extract patterns — phone numbers, IDs, dates — test your expression on real samples first. Watch out for nested quantifiers like (a+)+, which can hang on some inputs. The regex tester highlights matches, shows capture groups and stops runaway patterns.

Frequently asked questions

Is Base64 a form of encryption?

No. Base64 is reversible by anyone. It exists to carry binary data through systems that expect text. Never use it to protect passwords or secrets.

When should I escape HTML?

Whenever you insert untrusted text into an HTML page. Escaping & and < (and quotes inside attributes) stops the text being interpreted as markup, which helps prevent cross-site scripting.

Should I store timestamps in seconds or milliseconds?

Either works if you're consistent. Unix tools and many APIs use seconds; JavaScript's Date uses milliseconds. Name fields clearly, e.g. created_at_ms.

Tools mentioned

GitHub Copilot

AI Coding

GitHub’s AI pair programmer. It suggests code as you type and offers a chat assistant inside popular code editors and on GitHub itself.

Main use
Writing boilerplate faster
Free plan
Not yet verified
Pricing
Not yet verified
Last reviewed
Not yet reviewed

Cursor

AI Coding

An AI-first code editor built on the same foundations as Visual Studio Code. It lets you chat with your codebase and ask the AI to make…

Main use
Refactoring
Free plan
Not yet verified
Pricing
Not yet verified
Last reviewed
Not yet reviewed

You may also need

Free tools and pages that help with the same job.

Explore categories