Urgent.News

What's breaking now, across thousands of outlets.

Tech

How to Fix "Unexpected Token" and Other Invalid JSON Errors

Errors such as "Unexpected token } in JSON at position 42" or "Expected property name or '}'" almost always come from a small syntax slip. JSON is stricter than JavaScript object syntax, and it is easy to write something that looks fine but is not valid. These are the mistakes behind the vast majority of parse errors. 1. Trailing commas JSON does not allow a comma after the last item in an object…

This article explains how to resolve "Unexpected token" and similar invalid JSON errors that typically stem from small syntax mistakes. JSON has stricter syntax rules than JavaScript objects, so what looks fine in JavaScript may not be valid JSON. The most common error is trailing commas – JSON does not allow commas after the last item in an object or array.

For example, { a : 1 , b : 2 } is not valid JSON, whereas { a : 1 , b : 2 } is. Another frequent mistake is using single quotes instead of double quotes for strings and keys. In JSON, strings and keys must always be enclosed in double quotes, so { name : Ada } is valid, but { name : 'Ada' } is not. JSON also disallows unquoted keys, single-line comments, leading zeros, hex values, and newline/tab characters in strings.

Additionally, invisible issues like a byte-order mark at the start of a file or two objects back to back without a single enclosing object or array can cause parse errors. To quickly diagnose and fix these issues, copy the exact text being parsed and paste it into an online JSON validator, which will pinpoint the line and column of the first error.

The first character before the reported position usually reveals the mistake – a missing or extra comma, for instance. Fix the error one at a time and re-validate the JSON. If the error occurs at position 0, examine the raw response body and check the HTTP status code to ensure you're dealing with actual JSON and not an error page or HTML.

When working with API responses that may contain sensitive data, use a browser-based validator to avoid uploading private information to external servers.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Regex Cheatsheet for Beginners (With Copy-Paste Examples)

Regular expressions look cryptic at first, but a small set of building blocks covers most real-world tasks: validating input, searching logs, and doing bulk find-and-replace.

  • Dot character . matches any character except newline
  • Character classes like [abc] match specific options
  • Quantifiers specify occurrence counts like , +, ?

Base64 Is Not Encryption (And Other Common Misconceptions)

Base64 shows up everywhere: emails, data URLs, HTTP headers, JWTs. Because the output looks scrambled, it is often mistaken for encryption. It isn't.

  • Base64 is an encoding method, not encryption
  • It converts binary data to text format, reversible by anyone
  • Used for text-only channels, not providing secrecy

How Strong Should a Password Be? Length vs. Complexity

Password strength is really a question of how many guesses an attacker would need. Every extra character multiplies that number, which is why length matters far more than swapping an a for an @.

  • Length of password exponentially increases possible guesses for attacker
  • Entropy measures password unpredictability in bits, doubles with each bit
  • Passphrases made of random words offer strong security and memorability

JSON vs YAML: When to Use Which

JSON and YAML can describe the same data, so the choice comes down to who (or what) reads and writes the file. JSON is strict, small, and easy for software to parse.

  • JSON is strict and compact, ideal for software parsing
  • YAML is forgiving and user-friendly for humans
  • Use JSON for software-to-software data exchange

Why You Should Remove EXIF Data Before Sharing Photos

Every photo from a phone or camera carries a block of hidden information called EXIF (Exchangeable Image File Format) metadata.

  • Removing EXIF data before sharing photos prevents revealing personal information.
  • EXIF metadata includes device specifics, timestamps, and location data.
  • Use browser-based tools to strip metadata without uploading photos.

More from Saturday 26 September →