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…

Unexpected token and other invalid JSON errors typically arise due to small syntax mistakes. JSON is stricter than JavaScript object syntax, making it easy to write something that appears correct but is actually invalid. The most common error stems from trailing commas, which JSON does not allow after the last item in an object or array.

For instance, { a : 1 , b : 2 } is invalid, whereas { a : 1 , b : 2 } is correct. Additionally, JSON requires the use of double quotes for strings and keys, as single quotes are not permitted. Another frequent issue is the use of unquoted keys, which JavaScript allows but JSON does not. Comments are also not supported in standard JSON; instead, use JSONC, JSON5, YAML, or strip comments before parsing.

Values such as undefined, NaN, and Infinity are invalid, and numbers should not contain leading zeros or leading plus signs. Invisible issues, like a byte-order mark (BOM) at the beginning of a file or two objects back-to-back without a closing brace or bracket, can also cause unexpected token errors. To resolve these problems, copy the exact text being parsed and paste it into a validator, which should indicate the line and column of the first error. Focus on fixing one error at a time and re-validate to ensure the issue is resolved.

Brief written by urgent.news from Dev.to's own syndicated 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 →