<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Guo</title>
    <description>The latest articles on DEV Community by Guo (@toolexo).</description>
    <link>https://dev.to/toolexo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4122095%2F931d11ef-36af-4f9a-a2e6-8ee82c832439.png</url>
      <title>DEV Community: Guo</title>
      <link>https://dev.to/toolexo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/toolexo"/>
    <language>en</language>
    <item>
      <title>Base64 Is Not Encryption: A Practical Guide for Text and Small Files</title>
      <dc:creator>Guo</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:13:31 +0000</pubDate>
      <link>https://dev.to/toolexo/base64-is-not-encryption-a-practical-guide-for-text-and-small-files-5bhm</link>
      <guid>https://dev.to/toolexo/base64-is-not-encryption-a-practical-guide-for-text-and-small-files-5bhm</guid>
      <description>&lt;p&gt;Base64 often appears in places that make it look more mysterious than it is: API payloads, email attachments, Data URLs, configuration files, and token segments.&lt;/p&gt;

&lt;p&gt;It is easy to mistake a long Base64 string for protected data. It is not protected. Base64 is an encoding that represents bytes with printable text characters. Anyone who has the value can decode it.&lt;/p&gt;

&lt;p&gt;That distinction matters when you are handling text, small files, or values that might contain secrets.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Base64 actually does
&lt;/h2&gt;

&lt;p&gt;Computers store data as bytes. Base64 groups three bytes, or 24 bits, then splits those bits into four groups of six. Each six-bit value becomes one character from a 64-character alphabet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, the UTF-8 bytes for &lt;code&gt;cat&lt;/code&gt; become:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat  -&amp;gt;  Y2F0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The string &lt;code&gt;Y2F0&lt;/code&gt; looks different from &lt;code&gt;cat&lt;/code&gt;, but it contains no secret. Decode it and the original bytes return immediately.&lt;/p&gt;

&lt;p&gt;RFC 4648 defines the standard Base64 alphabet, padding behavior, and the URL-safe variant used by many web formats. &lt;a href="https://www.rfc-editor.org/info/rfc4648/" rel="noopener noreferrer"&gt;The RFC is worth reading when you need to implement or validate Base64 rather than simply call a library.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Base64 makes data larger
&lt;/h2&gt;

&lt;p&gt;Base64 encodes every three input bytes as four output characters.&lt;/p&gt;

&lt;p&gt;For input data with &lt;code&gt;n&lt;/code&gt; bytes, standard Base64 has this output length:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;4 × ceil(n / 3)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is roughly a 33% increase before you account for JSON quotes, a &lt;code&gt;data:&lt;/code&gt; URL prefix, or any transport overhead.&lt;/p&gt;

&lt;p&gt;A 3 MiB image does not become easier to send because it is Base64 encoded. It becomes larger, and placing that large string inside JSON or HTML can add parsing and memory costs.&lt;/p&gt;

&lt;p&gt;Base64 is useful when a system needs text-safe transport. It is not a compression format. If size is the problem, compress the original data or choose a more suitable file format.&lt;/p&gt;

&lt;h2&gt;
  
  
  The &lt;code&gt;=&lt;/code&gt; characters are padding, not data
&lt;/h2&gt;

&lt;p&gt;A Base64 string often ends in one or two &lt;code&gt;=&lt;/code&gt; characters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;YQ==    // "a"
YWI=    // "ab"
YWJj    // "abc"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The padding tells a decoder that the final input group contained one or two bytes instead of the usual three.&lt;/p&gt;

&lt;p&gt;Some protocols require standard padded Base64. Others define their own rules. A decoder should not quietly guess which form a value uses, especially when it is parsing structured data. Check the specification for the format you are working with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Base64URL is related, but not interchangeable
&lt;/h2&gt;

&lt;p&gt;Standard Base64 uses &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;/&lt;/code&gt;. Those characters can be awkward in URL paths, query strings, and filenames.&lt;/p&gt;

&lt;p&gt;Base64URL replaces them with &lt;code&gt;-&lt;/code&gt; and &lt;code&gt;_&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Standard Base64:  + and /
Base64URL:        - and _
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Base64URL commonly omits trailing &lt;code&gt;=&lt;/code&gt; padding as well.&lt;/p&gt;

&lt;p&gt;This is why the segments in a JWT often look like Base64 but do not contain &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;/&lt;/code&gt;, or &lt;code&gt;=&lt;/code&gt;. A JWT segment is usually Base64URL encoded JSON, not encrypted data. You can decode its header and payload, but you must not trust their contents until the signature has been verified.&lt;/p&gt;

&lt;p&gt;Use Base64URL only when the destination format expects it. Do not replace characters by habit and assume every Base64 decoder will accept the result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Text needs UTF-8 bytes first
&lt;/h2&gt;

&lt;p&gt;JavaScript strings are not byte arrays. This catches people when they try to use &lt;code&gt;btoa()&lt;/code&gt; directly with emoji, Chinese text, or other non-ASCII characters.&lt;/p&gt;

&lt;p&gt;This may work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;btoa&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This may throw or produce the wrong result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;btoa&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"你好"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The safe sequence is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Convert the JavaScript string to UTF-8 bytes.&lt;/li&gt;
&lt;li&gt;Encode those bytes as Base64.&lt;/li&gt;
&lt;li&gt;Reverse the process when decoding.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bytesToBase64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;binary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;byte&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;binary&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromCharCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;btoa&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;binary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;textToBase64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;bytesToBase64&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TextEncoder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;base64ToText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;binary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;atob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;binary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;char&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;char&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charCodeAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TextDecoder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"utf-8"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;fatal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;TextEncoder&lt;/code&gt; converts JavaScript strings to UTF-8 bytes, while &lt;code&gt;TextDecoder&lt;/code&gt; converts valid UTF-8 bytes back to text. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API" rel="noopener noreferrer"&gt;MDN's Encoding API reference explains this byte-to-text boundary.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;fatal: true&lt;/code&gt; when decoding is often the right choice for developer tools. It prevents arbitrary binary data from being silently presented as damaged text.&lt;/p&gt;

&lt;h2&gt;
  
  
  Binary files are not text
&lt;/h2&gt;

&lt;p&gt;A PNG, PDF, ZIP archive, or audio file can be Base64 encoded because Base64 works on bytes. That does not mean the decoded result is UTF-8 text.&lt;/p&gt;

&lt;p&gt;When you decode a Base64 file, the reliable workflow is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Decode the Base64 into bytes.&lt;/li&gt;
&lt;li&gt;Save those bytes as a file.&lt;/li&gt;
&lt;li&gt;Open the file with software that understands its format.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Trying to display arbitrary decoded bytes in a text area can corrupt the result or make it appear as unreadable characters.&lt;/p&gt;

&lt;p&gt;I built &lt;a href="https://toolexo.net/base64-encoder/" rel="noopener noreferrer"&gt;ToolExo's Base64 Encoder and Decoder&lt;/a&gt; around that distinction. It encodes UTF-8 text separately from local files, validates standard Base64 and Base64URL inputs, and lets you download decoded bytes as a file. File processing stays in the browser and is limited to 10 MiB, which keeps the tool suited to small local tasks rather than large asset pipelines.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data URLs are useful for small, deliberate cases
&lt;/h2&gt;

&lt;p&gt;A Data URL embeds data directly in a URL-like string:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They can be useful for tiny assets, test fixtures, or self-contained examples. They are usually a poor choice for normal application images.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Base64 payload increases the asset size.&lt;/li&gt;
&lt;li&gt;The browser cannot cache the embedded asset independently.&lt;/li&gt;
&lt;li&gt;A large inline string makes HTML, CSS, or JSON harder to inspect and maintain.&lt;/li&gt;
&lt;li&gt;Content Security Policy and browser behavior may limit where Data URLs are accepted.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data" rel="noopener noreferrer"&gt;MDN documents the &lt;code&gt;data:&lt;/code&gt; URL format and its practical limitations.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a normal website image, serve the file through a real URL. For a small one-off fixture or local prototype, a Data URL can be convenient.&lt;/p&gt;

&lt;h2&gt;
  
  
  Base64 does not protect secrets
&lt;/h2&gt;

&lt;p&gt;This is the part worth repeating.&lt;/p&gt;

&lt;p&gt;Do not Base64 encode a password, API key, private key, session token, database credential, or secret configuration value and call it protected. Encoding only changes representation.&lt;/p&gt;

&lt;p&gt;If you see this in a log:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;c3VwZXItc2VjcmV0LWtleQ==
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;assume it is exposed until proven otherwise. A decoder can recover the original value in seconds.&lt;/p&gt;

&lt;p&gt;Encryption requires a cryptographic algorithm and a key. Hashing has a different purpose again: it is designed to make recovery impractical, not to preserve the original bytes for later decoding.&lt;/p&gt;

&lt;p&gt;Base64 is appropriate when you need reversible binary-to-text conversion. It is the wrong tool when the goal is confidentiality.&lt;/p&gt;

&lt;h2&gt;
  
  
  A practical checklist
&lt;/h2&gt;

&lt;p&gt;Before encoding a value, ask:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do I need text-safe transport, or do I need secrecy?&lt;/li&gt;
&lt;li&gt;Is the receiving system expecting standard Base64 or Base64URL?&lt;/li&gt;
&lt;li&gt;Am I encoding UTF-8 text or arbitrary binary bytes?&lt;/li&gt;
&lt;li&gt;Will the 33% size increase create a problem?&lt;/li&gt;
&lt;li&gt;Should this file use a normal URL instead of a Data URL?&lt;/li&gt;
&lt;li&gt;Am I accidentally putting a secret into logs, source code, or client-side storage?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Base64 is simple once its job is clear. It moves bytes through text-only spaces. It does not compress those bytes, validate their meaning, or keep them private.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>security</category>
      <category>productivity</category>
    </item>
    <item>
      <title>What Makes a Password Generator Trustworthy in the Browser?</title>
      <dc:creator>Guo</dc:creator>
      <pubDate>Sat, 31 Oct 2026 03:16:24 +0000</pubDate>
      <link>https://dev.to/toolexo/what-makes-a-password-generator-trustworthy-in-the-browser-1e7h</link>
      <guid>https://dev.to/toolexo/what-makes-a-password-generator-trustworthy-in-the-browser-1e7h</guid>
      <description>&lt;p&gt;A password generator should do more than produce strings that look complicated.&lt;/p&gt;

&lt;p&gt;A trustworthy one needs a secure source of randomness, clear rules for how characters are selected, honest strength estimates, and a privacy model that does not claim more than the browser can guarantee. It also needs to fit into a wider account-security practice: unique passwords, a password manager, and multi-factor authentication where available.&lt;/p&gt;

&lt;p&gt;Here is what I look for when evaluating a browser-based password generator.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with the random source
&lt;/h2&gt;

&lt;p&gt;The first question is simple: where do the random characters come from?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Math.random()&lt;/code&gt; is fine for UI effects, demos, and many ordinary tasks. It is not a cryptographic random source, so it should not generate passwords.&lt;/p&gt;

&lt;p&gt;In a browser, the appropriate API is &lt;code&gt;crypto.getRandomValues()&lt;/code&gt;. It fills a typed array with cryptographically strong random values supplied by the browser's Web Crypto implementation. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues" rel="noopener noreferrer"&gt;MDN documents the API and its security purpose&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A basic pattern looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint32Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getRandomValues&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;values&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;values&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That alone is not the whole implementation, though. The generator still has to turn that random number into a character index correctly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid modulo bias
&lt;/h2&gt;

&lt;p&gt;Suppose a generator has an alphabet of 94 characters and chooses one with this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;randomValue&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A 32-bit random value has &lt;code&gt;2^32&lt;/code&gt; possible outputs. Since &lt;code&gt;2^32&lt;/code&gt; is not evenly divisible by 94, some character indexes occur slightly more often than others.&lt;/p&gt;

&lt;p&gt;The difference is small, but password generation is one of the places where there is no reason to accept it. A better approach uses rejection sampling:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find the largest multiple of the alphabet size that fits inside the random range.&lt;/li&gt;
&lt;li&gt;Discard values outside that range.&lt;/li&gt;
&lt;li&gt;Apply modulo only to the remaining values.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That keeps every permitted character equally likely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make policy choices explicit
&lt;/h2&gt;

&lt;p&gt;Many sites still require a particular mix of character types. A generator should let you choose among lowercase letters, uppercase letters, digits, and symbols, then make sure the result satisfies the selected policy.&lt;/p&gt;

&lt;p&gt;For example, if you enable all four groups, a generated password should contain at least one character from each group. It is not enough to draw from a combined alphabet and hope that every group appears.&lt;/p&gt;

&lt;p&gt;There is an important distinction here. NIST advises service operators not to force composition rules such as "one uppercase, one digit, one symbol" on passwords that users create themselves. Those rules often lead to predictable edits. But a generator still needs to meet the rule when a particular service requires it. &lt;a href="https://pages.nist.gov/800-63-4/sp800-63b.html" rel="noopener noreferrer"&gt;NIST's current guidance also emphasizes length, allowing long passwords, and avoiding arbitrary periodic password changes.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The practical rule is straightforward: follow the destination site's requirements, then make the password as long as the site accepts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Length usually buys more than clever punctuation
&lt;/h2&gt;

&lt;p&gt;A random password benefits directly from length. If every position can be chosen from an alphabet of &lt;code&gt;A&lt;/code&gt; characters and the password has length &lt;code&gt;L&lt;/code&gt;, the simple search space is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A^L
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Its approximate entropy in bits is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;L × log2(A)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Real generators may have extra constraints, such as requiring every selected character group to appear. In that case, an honest estimate should calculate the space of valid strings, not just show a generic score.&lt;/p&gt;

&lt;p&gt;Even then, "estimated entropy" is not a promise about account security or a prediction of crack time. It describes the generator's search space under its stated assumptions. Account security also depends on the site's password storage, rate limiting, recovery flow, phishing protections, and whether the password has been reused elsewhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  Local processing is useful, but it has limits
&lt;/h2&gt;

&lt;p&gt;For sensitive text, browser-only processing is a meaningful design choice. It avoids sending a newly generated password to a remote service just to create it.&lt;/p&gt;

&lt;p&gt;I built &lt;a href="https://toolexo.net/password-generator/" rel="noopener noreferrer"&gt;ToolExo's Password Generator&lt;/a&gt; to generate passwords locally with &lt;code&gt;crypto.getRandomValues()&lt;/code&gt;. It uses rejection sampling for character selection, supports a length from 8 to 128 characters, and calculates its estimate from the exact set of passwords allowed by the selected rules.&lt;/p&gt;

&lt;p&gt;"Local" does not mean the password disappears from every part of your device. The clipboard may be readable by other software. A browser extension, screen recording tool, sync service, or compromised machine changes the threat model. Treat a generated password as sensitive from the moment it appears.&lt;/p&gt;

&lt;p&gt;A generator can reduce exposure by hiding the output by default and allowing you to reveal or copy it only when needed. It cannot secure an unsafe endpoint.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ambiguous characters are a usability trade-off
&lt;/h2&gt;

&lt;p&gt;Characters such as &lt;code&gt;I&lt;/code&gt;, &lt;code&gt;l&lt;/code&gt;, &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;O&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt;, and &lt;code&gt;o&lt;/code&gt; are easy to confuse when a password must be read from a screen or typed manually.&lt;/p&gt;

&lt;p&gt;Removing them can be sensible for a password that will be entered by hand. The trade-off is a smaller character set, which slightly reduces the number of possible passwords. In most cases, adding a few more characters of length is a better fix than accepting a hard-to-read password.&lt;/p&gt;

&lt;p&gt;If a password manager fills the password automatically, ambiguity matters less. If you will type it into a console, device, or recovery screen, it matters more.&lt;/p&gt;

&lt;h2&gt;
  
  
  A generator is not a password manager
&lt;/h2&gt;

&lt;p&gt;A generator answers one question: "What should this password be?"&lt;/p&gt;

&lt;p&gt;A password manager handles the harder operational question: "How do I store a different strong password for every account and retrieve it safely later?"&lt;/p&gt;

&lt;p&gt;Unique passwords matter because reused credentials turn one breach into attempts against other services. NIST specifically notes that distinct passwords reduce password-stuffing risk, and its guidance discusses password-manager use. &lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html" rel="noopener noreferrer"&gt;OWASP also recommends allowing password-manager workflows and paste support in login forms.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For an important account, the working setup is usually:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate a long random password.&lt;/li&gt;
&lt;li&gt;Save it in a reputable password manager.&lt;/li&gt;
&lt;li&gt;Use that password for one account only.&lt;/li&gt;
&lt;li&gt;Enable multi-factor authentication when the service offers it.&lt;/li&gt;
&lt;li&gt;Change the password when there is evidence of compromise, not simply because a calendar reminder appeared.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A short checklist
&lt;/h2&gt;

&lt;p&gt;Before trusting a browser password generator, check whether it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;uses &lt;code&gt;crypto.getRandomValues()&lt;/code&gt; or an equivalent cryptographic source;&lt;/li&gt;
&lt;li&gt;maps random values to characters without modulo bias;&lt;/li&gt;
&lt;li&gt;clearly shows which character groups are enabled;&lt;/li&gt;
&lt;li&gt;guarantees the selected groups appear when required;&lt;/li&gt;
&lt;li&gt;treats entropy as an estimate, not a security guarantee;&lt;/li&gt;
&lt;li&gt;keeps generation in the browser when it claims to;&lt;/li&gt;
&lt;li&gt;explains clipboard and device-level limitations;&lt;/li&gt;
&lt;li&gt;helps you create passwords that work with a password manager.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A password generator does not need a dramatic interface or a vague "military grade" claim. It needs sound randomness, clear behavior, and enough honesty for you to understand what it does not protect.&lt;/p&gt;

</description>
      <category>security</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>UUID v4 vs v7: Choosing Identifiers for Modern Applications</title>
      <dc:creator>Guo</dc:creator>
      <pubDate>Sat, 31 Oct 2026 02:27:09 +0000</pubDate>
      <link>https://dev.to/toolexo/uuid-v4-vs-v7-choosing-identifiers-for-modern-applications-3ia6</link>
      <guid>https://dev.to/toolexo/uuid-v4-vs-v7-choosing-identifiers-for-modern-applications-3ia6</guid>
      <description>&lt;p&gt;UUIDs solve a simple problem: create identifiers without waiting for a database sequence or coordinating every new record through one central service.&lt;/p&gt;

&lt;p&gt;The usual choice used to be UUID v4. It is random, widely supported, and easy to generate. UUID v7 adds a useful difference: its first bits contain a Unix timestamp in milliseconds, which makes values broadly time-sortable.&lt;/p&gt;

&lt;p&gt;That makes v7 appealing for database records, event logs, and distributed systems. It does not make v4 obsolete.&lt;/p&gt;

&lt;p&gt;The right choice depends on what the identifier needs to do after you create it.&lt;/p&gt;

&lt;h2&gt;
  
  
  UUID v4 is random
&lt;/h2&gt;

&lt;p&gt;A UUID v4 has 128 bits in total. The version and variant consume some fixed bits, leaving 122 random bits.&lt;/p&gt;

&lt;p&gt;A typical v4 UUID looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;550e8400-e29b-41d4-a716-446655440000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;4&lt;/code&gt; at the start of the third group identifies the version. The next group begins with an RFC-defined variant value.&lt;/p&gt;

&lt;p&gt;The important property is that the value does not reveal when it was created or where it came from. With a cryptographically secure random source, UUID v4 is a good default when you need an identifier with no ordering requirement.&lt;/p&gt;

&lt;p&gt;In browsers, &lt;code&gt;crypto.randomUUID()&lt;/code&gt; generates a v4 UUID with a cryptographically secure random number generator. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID" rel="noopener noreferrer"&gt;MDN documents its v4 behavior&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Use v4 when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;records do not benefit from creation-time order;&lt;/li&gt;
&lt;li&gt;you want identifiers that do not expose their generation time;&lt;/li&gt;
&lt;li&gt;your existing system, library, or database convention already uses v4;&lt;/li&gt;
&lt;li&gt;simple random identifiers are enough.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  UUID v7 puts time first
&lt;/h2&gt;

&lt;p&gt;A UUID v7 looks familiar:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;018f4a8b-79c0-7b92-8c7f-123456789abc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key difference is the first 48 bits. They contain a Unix timestamp in milliseconds. The remaining non-reserved bits contain random data.&lt;/p&gt;

&lt;p&gt;That layout means UUID v7 values generated in different milliseconds generally sort in creation-time order when stored as their standard hexadecimal text representation or as comparable UUID bytes.&lt;/p&gt;

&lt;p&gt;RFC 9562 defines v7 as a Unix-time-based UUID with a 48-bit millisecond timestamp and random bits for uniqueness. It also allows implementations to add a sub-millisecond fraction or a carefully seeded counter when stricter ordering within the same millisecond is needed. &lt;a href="https://www.rfc-editor.org/rfc/rfc9562.html" rel="noopener noreferrer"&gt;RFC 9562&lt;/a&gt; is the current UUID specification.&lt;/p&gt;

&lt;p&gt;Use v7 when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;you insert many records into an ordered index;&lt;/li&gt;
&lt;li&gt;you want rough creation-time order without a separate timestamp field for every sort;&lt;/li&gt;
&lt;li&gt;you process event streams, audit records, or append-heavy tables;&lt;/li&gt;
&lt;li&gt;you want an identifier that is easier to inspect during debugging.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  "Time-sortable" is not "strictly ordered"
&lt;/h2&gt;

&lt;p&gt;This distinction matters.&lt;/p&gt;

&lt;p&gt;Suppose an application creates three v7 UUIDs in the same millisecond:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;018f4a8b-79c0-7b92-...
018f4a8b-79c0-7a11-...
018f4a8b-79c0-7f88-...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They share the same timestamp prefix. Their suffixes are random unless the generator implements an additional monotonic counter or sub-millisecond ordering strategy.&lt;/p&gt;

&lt;p&gt;ToolExo's UUID v7 generator uses the timestamp first and secure random data for the remaining payload. It does not claim to preserve creation order among UUIDs generated within the same millisecond.&lt;/p&gt;

&lt;p&gt;If your business logic needs a strict sequence, use an explicit sequence number, a database-generated ordering column, or a timestamp plus a deliberate tie-breaker. Do not infer strict event order from a v7 UUID alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Database locality is a reason, not a guarantee
&lt;/h2&gt;

&lt;p&gt;Random v4 UUIDs spread inserts across an index. That can be useful for distribution, but it may also produce less localized writes in some storage engines.&lt;/p&gt;

&lt;p&gt;UUID v7 values tend to cluster by creation time. For append-heavy workloads, that can reduce the amount of index churn compared with random identifiers.&lt;/p&gt;

&lt;p&gt;The practical result depends on your database, index type, storage layout, write pattern, and concurrency. It is worth testing with representative data rather than assuming that v7 will improve every workload.&lt;/p&gt;

&lt;p&gt;Also keep the creation timestamp as a separate column when your application needs precise filtering, reporting, retention policies, or database queries such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;NOW&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;INTERVAL&lt;/span&gt; &lt;span class="s1"&gt;'7 days'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A UUID v7 can help with ordering. It should not become a replacement for explicit data modeling.&lt;/p&gt;

&lt;h2&gt;
  
  
  v7 exposes approximate creation time
&lt;/h2&gt;

&lt;p&gt;A v4 UUID reveals no timestamp. A v7 UUID reveals its creation millisecond.&lt;/p&gt;

&lt;p&gt;That is useful when you inspect logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;018f4a8b-79c0-7b92-8c7f-123456789abc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A UUID inspector can read the timestamp prefix and show when the value was generated.&lt;/p&gt;

&lt;p&gt;It can also be a privacy consideration. If an identifier appears in a public URL, a client can infer roughly when the record was created. That may be harmless for a blog post or public event, but less desirable for some user-facing records.&lt;/p&gt;

&lt;p&gt;Choose v4 if hiding generation time matters more than chronological locality.&lt;/p&gt;

&lt;h2&gt;
  
  
  UUIDs are identifiers, not secrets
&lt;/h2&gt;

&lt;p&gt;A UUID identifies something. It should not be the only proof that someone is allowed to access it.&lt;/p&gt;

&lt;p&gt;Do not use a UUID as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a password;&lt;/li&gt;
&lt;li&gt;an API key;&lt;/li&gt;
&lt;li&gt;a session credential;&lt;/li&gt;
&lt;li&gt;a password-reset token;&lt;/li&gt;
&lt;li&gt;authorization logic by itself.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A cryptographically random UUID has a large random space, but identifiers are often logged, copied into URLs, stored in browser history, or exposed through APIs. Authentication and authorization need purpose-built controls.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generate with a secure source
&lt;/h2&gt;

&lt;p&gt;Do not build UUIDs from &lt;code&gt;Math.random()&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is not a cryptographically secure source. In the browser, use Web Crypto APIs such as &lt;code&gt;crypto.randomUUID()&lt;/code&gt; for v4 or &lt;code&gt;crypto.getRandomValues()&lt;/code&gt; when implementing an RFC-compliant generator yourself. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues" rel="noopener noreferrer"&gt;MDN explains &lt;code&gt;getRandomValues()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I built the &lt;a href="https://toolexo.net/uuid-generator/" rel="noopener noreferrer"&gt;ToolExo UUID Generator&lt;/a&gt; to generate RFC 9562 v4 and v7 UUID batches locally in the browser. It can also inspect an existing value, identify its version and variant, and show the embedded timestamp for a valid v7 UUID.&lt;/p&gt;

&lt;h2&gt;
  
  
  A practical choice
&lt;/h2&gt;

&lt;p&gt;Use UUID v4 when you want a random identifier with no embedded creation time.&lt;/p&gt;

&lt;p&gt;Use UUID v7 when chronological locality and rough time ordering are useful, especially for append-heavy records and operational debugging.&lt;/p&gt;

&lt;p&gt;Keep a separate &lt;code&gt;created_at&lt;/code&gt; field when time is part of your data model. Use a sequence or explicit ordering key when order within the same millisecond matters. And keep UUIDs out of authentication decisions.&lt;/p&gt;

&lt;p&gt;That gives each identifier one clear job, which is usually where UUID design goes right.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>database</category>
      <category>api</category>
      <category>webdev</category>
    </item>
    <item>
      <title>JSON Diffing in Practice: Keys, Arrays, Types, and Useful Paths</title>
      <dc:creator>Guo</dc:creator>
      <pubDate>Sat, 24 Oct 2026 12:42:47 +0000</pubDate>
      <link>https://dev.to/toolexo/json-diffing-in-practice-keys-arrays-types-and-useful-paths-55gk</link>
      <guid>https://dev.to/toolexo/json-diffing-in-practice-keys-arrays-types-and-useful-paths-55gk</guid>
      <description>&lt;p&gt;Comparing two JSON documents by text is often useful right up until it is not.&lt;/p&gt;

&lt;p&gt;A formatter can make two API responses look different because one serializer reordered object keys or changed indentation. A plain text diff then produces a wall of noise, even when the values are the same.&lt;/p&gt;

&lt;p&gt;The opposite problem is worse. A response can look almost identical while changing a number into a string, replacing &lt;code&gt;null&lt;/code&gt; with a missing property, or moving an array item. Those changes can break an API client without producing an obvious visual clue.&lt;/p&gt;

&lt;p&gt;A useful JSON diff starts by comparing structure, not presentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Object key order is usually noise
&lt;/h2&gt;

&lt;p&gt;Consider these two documents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"usr_42"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"editor"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"active"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"active"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"editor"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"usr_42"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A line-based diff reports several changes. Semantically, there are none.&lt;/p&gt;

&lt;p&gt;JSON objects are unordered collections of name and value pairs. That means a structural comparison should match object members by name, then compare their values, rather than treating their serialized position as meaningful. &lt;a href="https://www.rfc-editor.org/rfc/rfc8259.html" rel="noopener noreferrer"&gt;RFC 8259&lt;/a&gt; distinguishes this from arrays, which are ordered sequences.&lt;/p&gt;

&lt;p&gt;This is why formatting and key sorting are not enough for API reviews. They can make a document easier to read, but they cannot tell you whether the underlying structure changed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Array order is data
&lt;/h2&gt;

&lt;p&gt;Arrays need a different rule.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"steps"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"validate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"charge"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"notify"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"steps"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"charge"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"validate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"notify"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those arrays contain the same strings, but they do not mean the same thing if order controls execution.&lt;/p&gt;

&lt;p&gt;A structural JSON diff should compare array elements by index:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/steps/0: "validate" -&amp;gt; "charge"
/steps/1: "charge" -&amp;gt; "validate"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That result is more useful than saying that two lines moved. It identifies the values and the exact positions that changed.&lt;/p&gt;

&lt;p&gt;There is one limitation worth keeping in mind. An index-based diff cannot reliably infer whether an item was moved, deleted, or replaced when the array contains similar values. It reports what it can prove at each position. If your API has stable item IDs, a domain-specific comparison may be more useful for interpreting moves.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types matter even when the text looks close
&lt;/h2&gt;

&lt;p&gt;JSON has distinct types. A number is not a string, and &lt;code&gt;null&lt;/code&gt; is not the same as a missing property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"retryCount"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"region"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"retryCount"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"true"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A text-oriented comparison can bury these changes among punctuation and whitespace. A structural comparison should report them directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/retryCount: number -&amp;gt; string
/enabled: boolean -&amp;gt; string
/region: removed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first two changes may affect validation, sorting, arithmetic, and client code. The last one may change the meaning of the request entirely. A missing property often means "use a default" or "leave unchanged." A property set to &lt;code&gt;null&lt;/code&gt; can mean "clear this value."&lt;/p&gt;

&lt;p&gt;Do not collapse those cases into one generic "changed" result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read paths as locations, not labels
&lt;/h2&gt;

&lt;p&gt;A good diff needs paths that are short enough to scan and exact enough to act on.&lt;/p&gt;

&lt;p&gt;JSON Pointer is a standard syntax for locating a value inside a JSON document. Each path segment begins with &lt;code&gt;/&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"account"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"preferences"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"newsletter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value of &lt;code&gt;newsletter&lt;/code&gt; has this JSON Pointer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/account/preferences/newsletter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Arrays use their index:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"items"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"sku"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"A-12"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"sku"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"B-43"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second SKU is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/items/1/sku
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keys can contain characters with special meaning in a pointer. A slash in a key becomes &lt;code&gt;~1&lt;/code&gt;, and a tilde becomes &lt;code&gt;~0&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"a/b"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"m~n"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The path is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/a~1b/m~0n
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That escape rule comes from &lt;a href="https://www.rfc-editor.org/rfc/rfc6901.html" rel="noopener noreferrer"&gt;RFC 6901&lt;/a&gt;. It looks unusual at first, but it lets a diff report an unambiguous path even when object keys contain slashes.&lt;/p&gt;

&lt;h2&gt;
  
  
  A practical API response review
&lt;/h2&gt;

&lt;p&gt;Suppose an API response changes from this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"customer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cus_123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"creditLimit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"active"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"invoices"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"inv_1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"total"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"customer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cus_123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"creditLimit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"5000"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"active"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"riskLevel"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"review"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"invoices"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"inv_1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"total"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1200&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"inv_2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"total"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The useful review output is not a long block of changed lines. It is this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/customer/creditLimit: number -&amp;gt; string
/customer/riskLevel: added, value "review"
/invoices/1: added object
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That gives a developer three concrete questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Should &lt;code&gt;creditLimit&lt;/code&gt; still support numeric operations?&lt;/li&gt;
&lt;li&gt;Does the client need to handle &lt;code&gt;riskLevel&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Is the new invoice expected, or did pagination or filtering change?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A structural diff does not answer those questions. It makes sure they do not get lost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid misleading comparisons
&lt;/h2&gt;

&lt;p&gt;Before comparing JSON, validate both inputs as strict JSON.&lt;/p&gt;

&lt;p&gt;Duplicate object names are a problem because parsers may handle them differently. Large integer literals can also lose precision in JavaScript before a comparison begins. A tool should stop and explain those cases instead of silently producing a report that looks trustworthy.&lt;/p&gt;

&lt;p&gt;Keep the comparison scope clear too:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A JSON diff is not schema validation.&lt;/li&gt;
&lt;li&gt;A JSON diff is not an API compatibility guarantee.&lt;/li&gt;
&lt;li&gt;A JSON Pointer report is not a JSON Patch document.&lt;/li&gt;
&lt;li&gt;Equal JSON structures do not prove that business rules are still correct.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use a structural diff to find changes. Use tests, schemas, and the real integration to decide whether those changes are acceptable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compare structure without uploading the documents
&lt;/h2&gt;

&lt;p&gt;I built the &lt;a href="https://toolexo.net/json-diff-checker/" rel="noopener noreferrer"&gt;ToolExo JSON Diff Checker&lt;/a&gt; for this workflow. It parses both JSON documents locally, compares object members by key and arrays by index, and reports added, removed, changed, and type-changed values with JSON Pointer paths.&lt;/p&gt;

&lt;p&gt;Whitespace and object member order do not create differences. Array order, &lt;code&gt;null&lt;/code&gt;, missing properties, value changes, and type changes remain visible.&lt;/p&gt;

&lt;p&gt;That is the level of comparison most API reviews need. Less noise, clearer paths, and fewer cases where a meaningful change disappears inside a formatting diff.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>api</category>
      <category>testing</category>
      <category>webdev</category>
    </item>
    <item>
      <title>URL Encoding Explained: %20, +, Query Strings, and Common API Bugs</title>
      <dc:creator>Guo</dc:creator>
      <pubDate>Wed, 30 Sep 2026 16:36:26 +0000</pubDate>
      <link>https://dev.to/toolexo/url-encoding-explained-20-query-strings-and-common-api-bugs-47h3</link>
      <guid>https://dev.to/toolexo/url-encoding-explained-20-query-strings-and-common-api-bugs-47h3</guid>
      <description>&lt;p&gt;A URL is not one string with one encoding rule.&lt;/p&gt;

&lt;p&gt;It has a scheme, host, path, query string, fragment, and sometimes user-controlled values inside those parts. Bugs appear when code treats all of them as interchangeable text.&lt;/p&gt;

&lt;p&gt;The familiar examples are spaces encoded as &lt;code&gt;%20&lt;/code&gt; or &lt;code&gt;+&lt;/code&gt;, a literal plus sign that turns into a space, and an API request whose query parameters break when a user enters &lt;code&gt;&amp;amp;&lt;/code&gt; or &lt;code&gt;#&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The fix starts with a simple question: what exactly are you encoding?&lt;/p&gt;

&lt;h2&gt;
  
  
  Percent-encoding protects structure
&lt;/h2&gt;

&lt;p&gt;Some characters have structural meaning in a URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;? starts a query string
&amp;amp; separates query parameters
= separates a parameter name from its value
# starts a fragment
/ separates path segments
% begins a percent-encoded byte
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If one of those characters belongs to user-provided data, it must be encoded before it is placed into the relevant URL component.&lt;/p&gt;

&lt;p&gt;For example, this search term is data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;coffee &amp;amp; tea
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it is inserted directly into a query string, the &lt;code&gt;&amp;amp;&lt;/code&gt; can be read as the start of another parameter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://example.com/search?q=coffee &amp;amp; tea
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The intended value should instead be encoded:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://example.com/search?q=coffee%20%26%20tea
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Percent-encoding represents bytes with &lt;code&gt;%&lt;/code&gt; followed by hexadecimal digits. A space can become &lt;code&gt;%20&lt;/code&gt;, &lt;code&gt;&amp;amp;&lt;/code&gt; becomes &lt;code&gt;%26&lt;/code&gt;, and a literal plus sign becomes &lt;code&gt;%2B&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;MDN has a useful overview of &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding" rel="noopener noreferrer"&gt;percent-encoding in URLs&lt;/a&gt;, including why the same character may be encoded differently in different contexts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why &lt;code&gt;%20&lt;/code&gt; and &lt;code&gt;+&lt;/code&gt; both mean space sometimes
&lt;/h2&gt;

&lt;p&gt;This is where many API bugs begin.&lt;/p&gt;

&lt;p&gt;For an ordinary URL component, a space is commonly represented as &lt;code&gt;%20&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;summer sale&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// "summer%20sale"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;HTML form encoding uses a related but different convention. In &lt;code&gt;application/x-www-form-urlencoded&lt;/code&gt; data, a space is serialized as &lt;code&gt;+&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;campaign&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;summer sale&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// "campaign=summer+sale"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both strings can represent the same value in the right context.&lt;/p&gt;

&lt;p&gt;The important distinction is that a literal plus sign is not a space. If the original value is &lt;code&gt;C++ guide&lt;/code&gt;, a form-style query must encode the plus signs as &lt;code&gt;%2B&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;q&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C++ guide&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// "q=C%2B%2B+guide"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When that query string is parsed, &lt;code&gt;+&lt;/code&gt; becomes a space and &lt;code&gt;%2B&lt;/code&gt; becomes a literal plus sign.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;URLSearchParams&lt;/code&gt; follows the &lt;code&gt;application/x-www-form-urlencoded&lt;/code&gt; rules. MDN documents that its string parser decodes &lt;code&gt;+&lt;/code&gt; as a space, and its serializer writes spaces as &lt;code&gt;+&lt;/code&gt;. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams" rel="noopener noreferrer"&gt;Read the URLSearchParams reference&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;encodeURI&lt;/code&gt; and &lt;code&gt;encodeURIComponent&lt;/code&gt; solve different problems
&lt;/h2&gt;

&lt;p&gt;JavaScript provides two similarly named functions. They should not be swapped casually.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;encodeURI()&lt;/code&gt; assumes that the input is already a complete URI. It preserves URL punctuation such as &lt;code&gt;:&lt;/code&gt;, &lt;code&gt;/&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;, &lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;=&lt;/code&gt;, and &lt;code&gt;#&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;encodeURIComponent()&lt;/code&gt; is for one component or value. It encodes a wider set of characters, including &lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;=&lt;/code&gt;, and &lt;code&gt;#&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is unsafe when &lt;code&gt;value&lt;/code&gt; comes from a user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;coffee &amp;amp; tea&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`https://example.com/search?q=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;encodeURI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// https://example.com/search?q=coffee%20&amp;amp;%20tea&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;amp;&lt;/code&gt; remains structural. The server may interpret part of the value as another query parameter.&lt;/p&gt;

&lt;p&gt;For an individual value, use &lt;code&gt;encodeURIComponent()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;coffee &amp;amp; tea&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`https://example.com/search?q=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// https://example.com/search?q=coffee%20%26%20tea&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a full URL with query parameters, the &lt;code&gt;URL&lt;/code&gt; and &lt;code&gt;URLSearchParams&lt;/code&gt; APIs are usually clearer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://example.com/search&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;q&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;coffee &amp;amp; tea&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;searchParams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;source&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;docs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="c1"&gt;// https://example.com/search?q=coffee+%26+tea&amp;amp;source=docs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The serialized space appears as &lt;code&gt;+&lt;/code&gt; because &lt;code&gt;searchParams&lt;/code&gt; uses form-style query encoding. The value remains correct.&lt;/p&gt;

&lt;h2&gt;
  
  
  Encode values, not an entire URL by accident
&lt;/h2&gt;

&lt;p&gt;A common mistake is passing a complete URL through &lt;code&gt;encodeURIComponent()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://example.com/search?q=coffee&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// "https%3A%2F%2Fexample.com%2Fsearch%3Fq%3Dcoffee"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That output is useful only when the complete URL itself must become one value, such as a &lt;code&gt;redirect&lt;/code&gt; parameter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;redirect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://example.com/account?tab=billing&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`https://auth.example.com/login?redirect=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is not a replacement for constructing a normal URL.&lt;/p&gt;

&lt;p&gt;The reverse mistake is decoding a full URL or query string blindly. A decoded &lt;code&gt;&amp;amp;&lt;/code&gt;, &lt;code&gt;=&lt;/code&gt;, or &lt;code&gt;#&lt;/code&gt; may regain structural meaning in the wrong layer. Decode the component you expect, then validate what it means.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid double encoding
&lt;/h2&gt;

&lt;p&gt;Double encoding happens when already encoded text is treated as raw text and encoded again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;encodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello%20world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// "hello%2520world"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;%&lt;/code&gt; becomes &lt;code&gt;%25&lt;/code&gt;, so &lt;code&gt;%20&lt;/code&gt; becomes &lt;code&gt;%2520&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is sometimes intentional. It is often a sign that one layer of the application does not know whether it receives raw or encoded data.&lt;/p&gt;

&lt;p&gt;A practical rule helps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store and pass decoded values inside your application.&lt;/li&gt;
&lt;li&gt;Encode only when constructing the URL or request.&lt;/li&gt;
&lt;li&gt;Decode only when parsing a URL or request.&lt;/li&gt;
&lt;li&gt;Document any boundary that intentionally expects encoded text.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The same rule applies to &lt;code&gt;URLSearchParams&lt;/code&gt;. Give it raw keys and values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;q&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;coffee &amp;amp; tea&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not pre-encode the value before calling &lt;code&gt;set()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  URL encoding is not validation or security
&lt;/h2&gt;

&lt;p&gt;Encoding preserves URL structure. It does not prove that a URL is allowed, trustworthy, or safe to request.&lt;/p&gt;

&lt;p&gt;For example, percent-encoding does not:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;allowlist redirect destinations;&lt;/li&gt;
&lt;li&gt;prevent server-side request forgery;&lt;/li&gt;
&lt;li&gt;validate an API token;&lt;/li&gt;
&lt;li&gt;escape HTML for display in a page;&lt;/li&gt;
&lt;li&gt;make a query parameter safe for SQL;&lt;/li&gt;
&lt;li&gt;confirm that a URL uses HTTPS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those are separate checks with separate rules.&lt;/p&gt;

&lt;p&gt;If your application accepts a user-supplied URL, parse it with &lt;code&gt;new URL()&lt;/code&gt;, validate the protocol and host against the rules for that feature, and avoid using string replacement as a parser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the cases that tend to break
&lt;/h2&gt;

&lt;p&gt;When testing URL handling, do not stop at a simple word.&lt;/p&gt;

&lt;p&gt;Use values such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;summer sale
C++ guide
coffee &amp;amp; tea
a=b
100% ready
https://example.com/a?x=1
你好
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These cases reveal different failures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;spaces test &lt;code&gt;%20&lt;/code&gt; versus &lt;code&gt;+&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;+&lt;/code&gt; tests whether a literal plus survives form parsing;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;&lt;/code&gt; and &lt;code&gt;=&lt;/code&gt; test query-string structure;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;%&lt;/code&gt; tests malformed or double encoding;&lt;/li&gt;
&lt;li&gt;complete URLs test component boundaries;&lt;/li&gt;
&lt;li&gt;non-ASCII text tests UTF-8 encoding.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I built the &lt;a href="https://toolexo.net/url-encoder/" rel="noopener noreferrer"&gt;ToolExo URL Encoder and Decoder&lt;/a&gt; for this exact distinction. It keeps URL component encoding and form query-value encoding separate, shows &lt;code&gt;%20&lt;/code&gt; versus &lt;code&gt;+&lt;/code&gt;, encodes a literal plus as &lt;code&gt;%2B&lt;/code&gt; in form mode, and decodes only one layer at a time.&lt;/p&gt;

&lt;p&gt;The tool is for a single component or query value. It deliberately does not rewrite a complete URL, host name, or protocol. Those parts have their own structure and should be parsed as URLs, not treated as text.&lt;/p&gt;

&lt;p&gt;A URL bug often looks small in a log. It can be one missing &lt;code&gt;%26&lt;/code&gt;, one accidental &lt;code&gt;+&lt;/code&gt;, or one value encoded twice. Keeping the URL structure separate from its data values makes those bugs much easier to prevent.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>api</category>
      <category>security</category>
    </item>
    <item>
      <title>Regex Testers Can Freeze the Browser: Safer Testing with Timeouts</title>
      <dc:creator>Guo</dc:creator>
      <pubDate>Mon, 21 Sep 2026 04:37:20 +0000</pubDate>
      <link>https://dev.to/toolexo/regex-testers-can-freeze-the-browser-safer-testing-with-timeouts-e0d</link>
      <guid>https://dev.to/toolexo/regex-testers-can-freeze-the-browser-safer-testing-with-timeouts-e0d</guid>
      <description>&lt;p&gt;A regex can look harmless in code review and still lock up a page when someone pastes the wrong input.&lt;/p&gt;

&lt;p&gt;Most of us learn regular expressions as a compact way to validate a field, find a log line, or clean up text. The trouble starts when a pattern gives the engine many ways to interpret the same characters. If the match finally fails near the end of a long string, a backtracking engine may retry a huge number of possibilities before it gives up.&lt;/p&gt;

&lt;p&gt;That is how a small regex turns into a CPU problem.&lt;/p&gt;

&lt;p&gt;OWASP calls this Regular Expression Denial of Service, or ReDoS. The risk is not limited to servers. A bad pattern can block a browser tab, slow a worker, or tie up an API process if untrusted input reaches it. &lt;a href="https://community.owasp.org/attacks/Regular_expression_Denial_of_Service_-_ReDoS" rel="noopener noreferrer"&gt;OWASP's ReDoS overview&lt;/a&gt; includes examples of patterns that grow dramatically slower on carefully chosen non-matching input.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pattern that looks innocent
&lt;/h2&gt;

&lt;p&gt;Consider this regex:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/^&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It accepts one or more &lt;code&gt;a&lt;/code&gt; characters. The nested &lt;code&gt;+&lt;/code&gt; quantifiers create the problem.&lt;/p&gt;

&lt;p&gt;For a normal input, it seems fine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/^&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;aaaaaa&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now try a near miss:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pattern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;a+&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;+$/&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final &lt;code&gt;!&lt;/code&gt; prevents a match. Before the engine can return &lt;code&gt;false&lt;/code&gt;, it may try many ways to divide the preceding &lt;code&gt;a&lt;/code&gt; characters across the inner and outer repetitions.&lt;/p&gt;

&lt;p&gt;The issue is not that &lt;code&gt;+&lt;/code&gt; is always dangerous. The issue is ambiguity. If two repeated parts can consume the same characters, the engine has multiple routes to explore when the match fails.&lt;/p&gt;

&lt;p&gt;OWASP lists nested repetition and overlapping alternatives as common warning signs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(a+)+
(a*)*
(a|aa)+
([a-zA-Z]+)*$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A warning is not a proof that a regex is exploitable. It is a signal to test the pattern with realistic and hostile inputs before it reaches production.&lt;/p&gt;

&lt;h2&gt;
  
  
  The browser can be part of the failure
&lt;/h2&gt;

&lt;p&gt;JavaScript regular expressions run synchronously when you call methods such as &lt;code&gt;test&lt;/code&gt;, &lt;code&gt;exec&lt;/code&gt;, &lt;code&gt;match&lt;/code&gt;, or &lt;code&gt;replace&lt;/code&gt;. If a costly match runs on the main thread, the UI cannot repaint or respond to input until that work finishes.&lt;/p&gt;

&lt;p&gt;A test tool should isolate this work where possible. A Web Worker can run the regex outside the page's main UI thread. If the test does not finish within a bounded time, the page can terminate that worker and show a useful error instead of waiting forever.&lt;/p&gt;

&lt;p&gt;That protects the testing page. It does not prove the regex is safe in your application.&lt;/p&gt;

&lt;p&gt;A Node.js process, a Java service, a Python worker, and a browser tab may use different engines, time limits, input limits, and resource controls. Test the pattern where it will actually run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rewrite the pattern around the rule you mean
&lt;/h2&gt;

&lt;p&gt;The best fix is usually to remove the ambiguity.&lt;/p&gt;

&lt;p&gt;Suppose you want to allow words separated by spaces.&lt;/p&gt;

&lt;p&gt;This pattern has nested repetition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/^&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;w&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;?)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A clearer version describes the structure directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;/^&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;w&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(?:&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;w&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This says:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Match one word.&lt;/li&gt;
&lt;li&gt;Then match zero or more occurrences of one or more spaces followed by another word.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The second version also makes the intended rule easier to explain in a code review.&lt;/p&gt;

&lt;p&gt;Other practical safeguards help:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Put a maximum length on input before matching it.&lt;/li&gt;
&lt;li&gt;Prefer fixed, reviewed patterns over patterns assembled from user input.&lt;/li&gt;
&lt;li&gt;Test inputs that almost match but fail near the end.&lt;/li&gt;
&lt;li&gt;Avoid nested unbounded quantifiers when the repeated parts overlap.&lt;/li&gt;
&lt;li&gt;Apply server-side limits too. Client-side validation does not protect an API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The JavaScript &lt;code&gt;RegExp&lt;/code&gt; API is flexible, especially when patterns are built dynamically with the &lt;code&gt;RegExp()&lt;/code&gt; constructor. That flexibility deserves care when either the pattern or the text comes from an untrusted source. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp" rel="noopener noreferrer"&gt;MDN's RegExp reference&lt;/a&gt; documents the API and its constructor behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the happy path and the near miss
&lt;/h2&gt;

&lt;p&gt;A regex test case should include more than an example that matches.&lt;/p&gt;

&lt;p&gt;For a username pattern, test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;good_name
good-name
too short
a very long value
a value that fails at the final character
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a log parser, test long lines with one bad suffix. For a URL validator, test long repeated fragments and malformed delimiters. The inputs that fail late are often more informative than the inputs that pass immediately.&lt;/p&gt;

&lt;h2&gt;
  
  
  A timeout is a guardrail, not a certificate
&lt;/h2&gt;

&lt;p&gt;I built the &lt;a href="https://toolexo.net/regex-tester/" rel="noopener noreferrer"&gt;ToolExo Regex Tester&lt;/a&gt; to run JavaScript regex evaluations in a disposable Web Worker. The tool terminates work that exceeds 500 milliseconds and flags a few risky shapes, such as nested repetition and repeated alternatives with overlapping branches.&lt;/p&gt;

&lt;p&gt;The timeout keeps one experiment from trapping the tester. It does not certify a pattern as safe, and it does not transfer its protection to another runtime.&lt;/p&gt;

&lt;p&gt;Use the tool to inspect matches, capture groups, replacements, and difficult test cases. Then test the same pattern with your production input limits and runtime configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the rule simple enough to defend
&lt;/h2&gt;

&lt;p&gt;A regular expression is easier to maintain when you can explain what each repeated section consumes and why it cannot compete with another section for the same input.&lt;/p&gt;

&lt;p&gt;If that explanation becomes hard, split the job:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use a simple regex to check broad syntax.&lt;/li&gt;
&lt;li&gt;Parse or validate the meaningful parts in ordinary code.&lt;/li&gt;
&lt;li&gt;Enforce length and business rules separately.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This approach often produces clearer error messages as well. A user learns whether a value is too long, has an invalid character, or fails a business rule. They do not get a generic "invalid input" message from a pattern nobody wants to edit.&lt;/p&gt;

&lt;p&gt;Regex remains useful. It just needs the same care we give database queries, file parsers, and every other piece of code that processes untrusted input.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>security</category>
      <category>testing</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to format and validate JSON without uploading it anywhere</title>
      <dc:creator>Guo</dc:creator>
      <pubDate>Sat, 12 Sep 2026 12:06:27 +0000</pubDate>
      <link>https://dev.to/toolexo/how-to-format-and-validate-json-without-uploading-it-anywhere-37fm</link>
      <guid>https://dev.to/toolexo/how-to-format-and-validate-json-without-uploading-it-anywhere-37fm</guid>
      <description>&lt;p&gt;A JSON blob is often easiest to read after it has been formatted. That sounds harmless until the blob is an API response with customer data, a production configuration file, or a test fixture copied from somewhere you should not casually share.&lt;/p&gt;

&lt;p&gt;The usual workflow is simple: paste it into a formatter, make it readable, copy it back.&lt;/p&gt;

&lt;p&gt;The problem is that the formatter may be another service in the data path.&lt;/p&gt;

&lt;p&gt;For ordinary sample data, that may not matter. For production payloads, credentials, tokens, private URLs, or customer records, it should make you stop before pasting. A local formatter is useful because parsing and formatting can happen in the browser instead of requiring a request to a server. It is still not a license to paste secrets everywhere. Clipboard history, browser extensions, screenshots, and the system you later paste into remain part of the risk.&lt;/p&gt;

&lt;p&gt;This article covers a practical local JSON workflow, what browser validation actually proves, and where its limits begin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with strict JSON, not JavaScript-like JSON
&lt;/h2&gt;

&lt;p&gt;JSON and JavaScript object literals look similar. They are not the same format.&lt;/p&gt;

&lt;p&gt;This is valid JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;settings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;retryCount&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is not valid JSON. JSON requires double-quoted property names and string values. It also does not allow trailing commas.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"theme"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"dark"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"retryCount"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That distinction matters when you are preparing data for an API, a &lt;code&gt;package.json&lt;/code&gt; file, or another strict JSON consumer. The JSON specification defines a limited data model: objects, arrays, strings, numbers, booleans, and &lt;code&gt;null&lt;/code&gt;. It does not include comments, functions, &lt;code&gt;undefined&lt;/code&gt;, &lt;code&gt;NaN&lt;/code&gt;, &lt;code&gt;Infinity&lt;/code&gt;, or JavaScript shorthand syntax. &lt;a href="https://www.rfc-editor.org/rfc/rfc8259" rel="noopener noreferrer"&gt;RFC 8259&lt;/a&gt; is the useful reference when a format dispute turns into a production bug.&lt;/p&gt;

&lt;p&gt;Do not use &lt;code&gt;eval()&lt;/code&gt; to "fix" JSON-like text. It turns data handling into code execution. If the input is JSON5, YAML, or a JavaScript configuration module, identify that format and use a parser intended for it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What formatting does, and what it does not do
&lt;/h2&gt;

&lt;p&gt;A formatter normally does two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Parse the text into a value.&lt;/li&gt;
&lt;li&gt;Serialize that value again with chosen indentation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In browser JavaScript, that often means &lt;code&gt;JSON.parse()&lt;/code&gt; followed by &lt;code&gt;JSON.stringify()&lt;/code&gt;. MDN documents both APIs and their edge cases, including serialization behavior for values that JSON cannot represent directly. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse" rel="noopener noreferrer"&gt;JSON.parse()&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify" rel="noopener noreferrer"&gt;JSON.stringify()&lt;/a&gt; are worth reading if you regularly move data between JavaScript and APIs.&lt;/p&gt;

&lt;p&gt;Formatting makes structure visible:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"service"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"billing"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"limits"&lt;/span&gt;&lt;span class="p"&gt;:{&lt;/span&gt;&lt;span class="nl"&gt;"daily"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;250&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"monthly"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"service"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"billing"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"limits"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"daily"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;250&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"monthly"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That makes missing brackets, unexpected nesting, and confusing field names easier to spot.&lt;/p&gt;

&lt;p&gt;It does not prove that the data is correct for your application.&lt;/p&gt;

&lt;p&gt;A valid JSON document can still have a wrong field name, an expired identifier, a string where an API expects a number, or an unsafe permission setting. Syntax validation is the first check, not the last one.&lt;/p&gt;

&lt;h2&gt;
  
  
  A safer local workflow
&lt;/h2&gt;

&lt;p&gt;For non-sensitive JSON, I use this sequence:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Remove secrets before copying anything. That includes API keys, bearer tokens, passwords, signed URLs, session values, and customer data.&lt;/li&gt;
&lt;li&gt;Validate the original text before changing it.&lt;/li&gt;
&lt;li&gt;Format it only after it passes strict parsing.&lt;/li&gt;
&lt;li&gt;Compare important values against the source, especially IDs, URLs, amounts, flags, and ordered arrays.&lt;/li&gt;
&lt;li&gt;Test the final JSON with the actual destination system.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first step is not optional just because a tool claims local processing. OWASP advises against placing sensitive data in browser storage, and browser-side handling has risks that go beyond network transmission. &lt;a href="https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/11-Client-side_Testing/12-Testing_Browser_Storage" rel="noopener noreferrer"&gt;OWASP Web Storage guidance&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a browser-based workspace, I built &lt;a href="https://toolexo.net/json-formatter/" rel="noopener noreferrer"&gt;ToolExo JSON Formatter and Validator&lt;/a&gt;. It uses the browser's strict JSON parser to validate, format, minify, or optionally sort object keys. It reports invalid syntax instead of silently adding quotes, removing comments, or guessing what malformed input was meant to say.&lt;/p&gt;

&lt;p&gt;That last part is deliberate. Silent repair can hide the bug that generated the bad JSON in the first place.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common errors worth recognizing
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Trailing commas
&lt;/h3&gt;

&lt;p&gt;This is one of the most common cases where JavaScript habits leak into JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"environment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"staging"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"debug"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The comma after &lt;code&gt;false&lt;/code&gt; is invalid because no next property follows it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"environment"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"staging"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"debug"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Single quotes
&lt;/h3&gt;

&lt;p&gt;JSON strings use double quotes only.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;'status':&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;'ready'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Correct JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ready"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Unquoted property names
&lt;/h3&gt;

&lt;p&gt;This is valid in a JavaScript object literal but invalid in JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Correct JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"timeout"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Comments
&lt;/h3&gt;

&lt;p&gt;JSON does not support comments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;used&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;by&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;nightly&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;job&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the destination expects JSON, move that explanation into documentation or a field with an agreed meaning. Do not assume a comment-tolerant editor means the receiving system will accept it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Be careful when sorting keys
&lt;/h2&gt;

&lt;p&gt;Sorting object keys can make reviews and diffs easier. It should not change the meaning of a normal JSON object, but it changes the text.&lt;/p&gt;

&lt;p&gt;That matters if another system signs the original bytes, compares snapshots as text, or expects a defined canonicalization scheme. Array order is different. Arrays are ordered, so a formatter should not reorder their elements just because it can sort object keys.&lt;/p&gt;

&lt;p&gt;If you are about to replace a file used in production, keep the original, save the formatted version as a new file, and test the new file where it will actually run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Large integers and duplicate keys need extra attention
&lt;/h2&gt;

&lt;p&gt;JavaScript numbers use IEEE 754 floating-point representation. A JSON integer may be syntactically valid but lose precision when parsed into a JavaScript &lt;code&gt;Number&lt;/code&gt;. For identifiers, account numbers, or exact counters, use a documented string representation if precision matters.&lt;/p&gt;

&lt;p&gt;Duplicate object keys are another interoperability trap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"region"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"us-east-1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"region"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"eu-west-1"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Different parsers can handle duplicate names differently. Many JavaScript workflows keep the later value, but relying on that behavior makes the data ambiguous. Reject or fix duplicate names at the source.&lt;/p&gt;

&lt;h2&gt;
  
  
  Formatting is a debugging aid, not a schema
&lt;/h2&gt;

&lt;p&gt;A JSON formatter answers a narrow question: "Can this text be parsed as JSON?"&lt;/p&gt;

&lt;p&gt;It cannot answer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does this payload match the API schema?&lt;/li&gt;
&lt;li&gt;Are all required fields present?&lt;/li&gt;
&lt;li&gt;Is this user allowed to submit the request?&lt;/li&gt;
&lt;li&gt;Does the number use the correct unit?&lt;/li&gt;
&lt;li&gt;Is the URL safe to fetch?&lt;/li&gt;
&lt;li&gt;Does the data make sense for the business rule?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use schema validation, server-side authorization, field validation, and integration tests for those questions.&lt;/p&gt;

&lt;p&gt;Formatting earns its place earlier in the workflow. It makes a compact response readable, exposes a syntax error before you chase the wrong problem, and helps you review the shape of data without sending it to a third-party formatter.&lt;/p&gt;

&lt;p&gt;That is enough to make it a useful tool. It just should not be confused with a security boundary or a full validation system.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>security</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
