Urgent.News

What's breaking now, across thousands of outlets.

Tech

5 Common JSON Mistakes That Break API Requests (With Fixes)

JSON is one of the most common formats used to exchange data between frontend applications, backend services, and APIs. It looks similar to a JavaScript object, but JSON has stricter syntax rules. A small mistake can cause a request body to fail parsing, produce an HTTP 400 response, or prevent automated tests from running correctly. Here are five common mistakes, how to fix them, and how to…

JSON is a widely used format for exchanging data between different parts of applications. It has strict syntax rules, so even minor mistakes can cause parsing errors or HTTP 400 responses. Here are five common issues developers make when serializing data as JSON, along with fixes.

1. Using single quotes instead of double quotes. JSON requires double quotes for property names and string values. JavaScript allows single-quoted strings in object literals, but not in JSON. So { name : Dinesh , role : QA Engineer } is invalid JSON, while { "name" : "Dinesh" , "role" : "QA Engineer" } is valid.

2. Adding trailing commas. JavaScript permits trailing commas in object and array literals, but standard JSON does not. So { name : Dinesh , skills : [ JavaScript , Playwright ] } is incorrect JSON. Remove the comma after the closing bracket to make it valid JSON: { "name" : "Dinesh" , "skills" : [ "JavaScript" , "Playwright" ] }.

3. Including comments. Standard JSON does not support comments. Comments are not part of the JSON specification and will cause parsing errors. So { // Application configuration environment : test , retries : 3 } is invalid JSON. Remove the comments to get valid JSON: { "environment" : "test" , "retries" : 3 }.

4. Using JavaScript values not supported by JSON. JSON supports strings, numbers, booleans, null, arrays, and objects. But it does not support JavaScript values like undefined, NaN, or date literals created with new Date(). So { user : undefined , createdAt : new Date() , score : NaN } is invalid JSON. Replace those values with appropriate JSON types, maybe { "user" : null , "createdAt" : "2026-10-17T10:30:00Z" , "score" : 0 }.

5. Forgetting to escape special characters. In JSON strings, certain characters like double quotes and backslashes need to be escaped with a backslash. So { message : He said "Hello" to me } breaks JSON because the inner quotes terminate the string. The correct version is { "message" : "He said \\\"Hello\\\" to me" }. Similarly, escape backslashes and control characters correctly.

To validate JSON in JavaScript, use JSON.parse() inside a try-catch block. If parsing succeeds, the input is valid JSON. But even valid JSON may not conform to an API's schema or business rules. So while { "email" : 123 } is valid JSON, it may not be an acceptable value for an email address field in an API request.

When sending JSON with fetch(), first serialize the JavaScript object to a string using JSON.stringify(). Then pass that string to fetch() as the request body, specifying the Content-Type header as application/json. The server can then parse the incoming JSON and validate it against its own schema.

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

SameSite=Lax doesn't protect you from login-CSRF | Xiliux Blog

We built an identity server — Bachué — with password login, a second factor, and cookie sessions. The cookies carry SameSite=Lax , and we took for granted what "everyone knows": that SameSite=Lax…

  • Bachué identity server tested for CSRF protection
  • SameSite=Lax cookies insufficient against CSRF
  • Login-CSRF vulnerability found, not covered by SameSite

PwnEscape: Guest-to-Host KVM Escape (CVE-2026-99999)

  • Vercel launched $1 million challenge to test Sandbox product isolation in August 2026
  • Researchers discovered Linux networking vulnerability allowing guest code to rewrite IPv4 header
  • Vercel handled vulnerability well, coordinating disclosure and fixes across industry

How I Built a Multi-Agent Micro-SaaS Orchestration Engine in n8n (Zero Cloud Subscriptions)

Building scalable, multi-agent AI systems usually means falling into one of two traps: drowning in the spaghetti code of Python-based orchestration libraries, or bleeding monthly recurring revenue to…

  • Author builds Micro-SaaS Agent Farm & Sub-Agent Orchestration Engine in n8n
  • Proposes Master/Worker model with parallel worker agents for tasks
  • Provides JavaScript, Python, and LLM prompt structuring for seamless handoffs

More from Saturday 17 October →