<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[GoToolsOnline Dev Notes]]></title><description><![CDATA[GoToolsOnline Dev Notes]]></description><link>https://gotoolsonline.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 20 Nov 2026 18:01:17 GMT</lastBuildDate><atom:link href="https://gotoolsonline.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How barcode check digits work (EAN-13 and UPC-A, with a 10-line function)]]></title><description><![CDATA[The last digit of an EAN-13 or UPC-A barcode isn't part of the product number. It's a check digit, there so a scanner can catch a misread. Take the first…]]></description><link>https://gotoolsonline.hashnode.dev/how-barcode-check-digits-work-ean-13-and-upc-a-with-a-10-line-function</link><guid isPermaLink="true">https://gotoolsonline.hashnode.dev/how-barcode-check-digits-work-ean-13-and-upc-a-with-a-10-line-function</guid><category><![CDATA[barcode]]></category><category><![CDATA[ecommerce]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[GoToolsOnline]]></dc:creator><pubDate>Sat, 14 Nov 2026 10:44:27 GMT</pubDate><content:encoded><![CDATA[<p>The last digit of an EAN-13 or UPC-A barcode isn't part of the product number. It's a check digit, there so a scanner can catch a misread.</p>
<h2>The EAN-13 rule</h2>
<p>Take the first 12 digits. Counting from the left, multiply digits in odd positions by 1 and digits in even positions by 3. Add everything up. The check digit is whatever brings the total up to the next multiple of 10.</p>
<p>Example: <code>400638133393?</code></p>
<ul>
<li>Odd positions (1st, 3rd, 5th…): 4+0+3+1+3+9 = 20</li>
<li>Even positions: (0+6+8+3+3+3) × 3 = 23 × 3 = 69</li>
<li>Total = 89, next multiple of 10 is 90, so the check digit is <strong>1</strong> → <code>4006381333931</code></li>
</ul>
<p>UPC-A (12 digits) uses the same idea but weights from the right, so the first digit gets ×3. A handy trick: UPC-A is just EAN-13 with a leading 0, so one function covers both.</p>
<pre><code class="language-js">function gtinCheckDigit(body) {
  // body: digits without the check digit (7, 11, 12 or 13 long)
  let sum = 0;
  for (let i = 0; i &lt; body.length; i++) {
    const d = Number(body[body.length - 1 - i]);
    sum += i % 2 === 0 ? d * 3 : d; // rightmost body digit gets x3
  }
  return (10 - (sum % 10)) % 10;
}
gtinCheckDigit("400638133393"); // 1
</code></pre>
<p>Weighting from the right is why this works for EAN-8, UPC-A, EAN-13 and ITF-14 alike.</p>
<h2>What it catches (and doesn't)</h2>
<p>The ×1/×3 pattern catches every single-digit error and most swaps of two neighbouring digits. It won't catch a swap of two digits that differ by 5 (like 1 and 6), so it's a sanity check, not a guarantee.</p>
<h2>A practical warning</h2>
<p>Making a valid-looking EAN-13 is easy; making a <em>real</em> one isn't. Retail product codes come from GS1 (the number prefix identifies the company that licensed it), so for anything sold through a retailer you need GS1-assigned numbers. For internal use (stock bins, asset tags) Code 128 is usually a better fit anyway.</p>
<p>Disclosure: I run GoToolsOnline. Its free barcode generator works in the browser, calculates and checks the check digit for EAN/UPC/ITF-14, warns about GS1 issues, and exports PNG (incl. 300 dpi) or SVG: <a href="https://gotoolsonline.com/tools/barcode-generator">https://gotoolsonline.com/tools/barcode-generator</a></p>
]]></content:encoded></item><item><title><![CDATA[Why your JSON won't parse: the 6 usual suspects (and how to format it safely in the browser)]]></title><description><![CDATA[Unexpected token } in JSON at position 214 is one of the most common errors a developer sees, and it is almost always one of a handful of mistakes. JSON…]]></description><link>https://gotoolsonline.hashnode.dev/why-your-json-won-t-parse-the-6-usual-suspects-and-how-to-format-it-safely-in-the-browser</link><guid isPermaLink="true">https://gotoolsonline.hashnode.dev/why-your-json-won-t-parse-the-6-usual-suspects-and-how-to-format-it-safely-in-the-browser</guid><category><![CDATA[json]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[webdev]]></category><category><![CDATA[Beginner Developers]]></category><dc:creator><![CDATA[GoToolsOnline]]></dc:creator><pubDate>Sat, 17 Oct 2026 07:03:03 GMT</pubDate><content:encoded><![CDATA[<p><code>Unexpected token } in JSON at position 214</code> is one of the most common errors a developer sees, and it is almost always one of a handful of mistakes. JSON looks like JavaScript, but it is much stricter.</p>
<h3>The usual suspects</h3>
<ol>
<li><p><strong>Trailing commas.</strong> <code>{"a": 1, "b": 2,}</code> is valid in a JS object literal but invalid JSON. Same for <code>[1, 2, 3,]</code>.</p>
</li>
<li><p><strong>Single quotes.</strong> JSON strings and keys must use double quotes: <code>{'name': 'x'}</code> fails.</p>
</li>
<li><p><strong>Unquoted keys.</strong> <code>{name: "x"}</code> is JS, not JSON.</p>
</li>
<li><p><strong>Comments.</strong> /<code>/</code> and <code>/* */</code> are not allowed in JSON. If you need comments in config, use JSONC/JSON5 tooling that strips them first.</p>
</li>
<li><p><strong>Non-JSON values.</strong> <code>NaN</code>, <code>Infinity</code>, <code>undefined</code> and functions do not exist in JSON. <code>JSON.stringify</code> silently drops <code>undefined</code> and turns <code>NaN</code> into <code>null</code>.</p>
</li>
<li><p><strong>Several documents in one paste.</strong> Line-delimited JSON (one object per line, common in logs) is not one JSON document. Parse it line by line, or wrap the lines in <code>[ ]</code> with commas between them.</p>
</li>
</ol>
<h3>Bonus: an invisible BOM at the start of the file</h3>
<p>If you read a JSON file from disk and JSON.parse fails on the very first character, the file may start with a byte order mark (BOM, the bytes EF BB BF). Most editors don't show it, and the error message gives no hint. Re-save the file as "UTF-8" (not "UTF-8 with BOM"), or strip it in code first, for example <code>text.replace(/^\uFEFF/, '')</code> before parsing. Thanks to StackShortlist for this tip in the comments.</p>
<h3>Read the position in the error</h3>
<p>The parser's message usually gives the index of the first bad character. In Node or the browser console:</p>
<pre><code class="language-js">try {
  JSON.parse(text);
} catch (e) {
  console.log(e.message); // e.g. "... at position 214"
  console.log(text.slice(200, 230)); // look around that spot
}
</code></pre>
<p>The real mistake is often just before that position, for example a missing comma or quote on the previous line.</p>
<h3>Format vs minify</h3>
<ul>
<li><p><strong>Format</strong> (pretty-print) rewrites the same data with line breaks and indentation: <code>JSON.stringify(JSON.parse(text), null, 2)</code>.</p>
</li>
<li><p><strong>Minify</strong> removes optional whitespace: <code>JSON.stringify(JSON.parse(text))</code>. Neither changes keys, values or key order.</p>
</li>
</ul>
<h3>Be careful where you paste</h3>
<p>Many online formatters send your paste to a server. If the JSON contains API responses with personal data, tokens or internal IDs, prefer a tool that runs entirely client-side, or just use the two one-liners above in your console.</p>
<h3>A client-side option</h3>
<p>I run gotoolsonline.com, a free tools site. Its JSON formatter does Format, Minify and validation with JavaScript in your tab, so the JSON you paste is not sent to our server, and invalid input shows the browser parser's error so you can jump to the problem. No sign-up.</p>
<p><a href="https://gotoolsonline.com/tools/json-formatter">https://gotoolsonline.com/tools/json-formatter</a></p>
<p>(Disclosure: I built and run this site. Still avoid pasting live secrets on a shared screen.)</p>
]]></content:encoded></item></channel></rss>