<?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: ARPAN NANDI</title>
    <description>The latest articles on DEV Community by ARPAN NANDI (@apscot).</description>
    <link>https://dev.to/apscot</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3504759%2F5689c44f-b950-4983-9162-d404cb734296.jpg</url>
      <title>DEV Community: ARPAN NANDI</title>
      <link>https://dev.to/apscot</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/apscot"/>
    <language>en</language>
    <item>
      <title>The Hidden Costs of JSON in APIs</title>
      <dc:creator>ARPAN NANDI</dc:creator>
      <pubDate>Mon, 15 Sep 2025 20:12:46 +0000</pubDate>
      <link>https://dev.to/apscot/the-hidden-costs-of-json-in-apis-4m4h</link>
      <guid>https://dev.to/apscot/the-hidden-costs-of-json-in-apis-4m4h</guid>
      <description>&lt;p&gt;If you’ve built APIs for any length of time, you’ve probably defaulted to JSON without a second thought.&lt;/p&gt;

&lt;p&gt;It’s the lingua franca of the web: easy to read, easy to generate, supported everywhere.&lt;/p&gt;

&lt;p&gt;What could possibly be wrong?&lt;/p&gt;

&lt;p&gt;Well, like that “free” trial subscription you forgot to cancel, JSON comes with hidden costs that only show up later — usually when your API is under real load, or your data model starts growing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Quick History Lesson: XML → JSON → ???&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Remember when XML was the default for APIs?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verbose tags everywhere&lt;/li&gt;
&lt;li&gt;Endless angle brackets&lt;/li&gt;
&lt;li&gt;Painful parsing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JSON felt like a breath of fresh air — shorter, cleaner, more readable.&lt;/p&gt;

&lt;p&gt;But here’s the catch: JSON is also verbose. Maybe not as bad as XML, but once your payloads start growing, you’ll realize it still carries a lot of unnecessary weight.&lt;/p&gt;

&lt;p&gt;So, we essentially traded one kind of verbosity for another.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Verbosity = Bigger Payloads&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s a simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "id": 123,
  "username": "john_doe",
  "isActive": true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks innocent enough. But as your data model grows, every field name gets repeated, every nested object gets wrapped in braces.&lt;/p&gt;

&lt;p&gt;Compare that with a binary format like Protobuf: the same data can be represented in fewer bytes — sometimes 5x smaller.&lt;/p&gt;

&lt;p&gt;At scale, verbosity means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Higher bandwidth costs&lt;/li&gt;
&lt;li&gt;Slower network transfer&lt;/li&gt;
&lt;li&gt;More time spent parsing large payloads&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Parsing Overhead&lt;br&gt;
JSON parsing is CPU-intensive compared to binary formats.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A classic example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ObjectMapper mapper = new ObjectMapper();
User user = mapper.readValue(json, User.class);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple, right? But behind the scenes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The parser scans every character.&lt;/li&gt;
&lt;li&gt;Validates structure.&lt;/li&gt;
&lt;li&gt;Maps to strings, numbers, booleans.&lt;/li&gt;
&lt;li&gt;Then builds Java objects.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On a single request, no big deal. On 10k requests per second? Suddenly your CPU is working overtime just to shuffle text into objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Numbers Are… Tricky&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JSON doesn’t distinguish between integer sizes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;123&lt;/code&gt; could be an &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, or &lt;code&gt;BigInteger&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;123.45&lt;/code&gt; might be a &lt;code&gt;float&lt;/code&gt;, &lt;code&gt;double&lt;/code&gt;, or &lt;code&gt;BigDecimal&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I once had a production bug where a JSON field holding an order ID (&lt;code&gt;1234567890123456789&lt;/code&gt;) silently lost precision because the client treated it as a double.&lt;/p&gt;

&lt;p&gt;Lesson learned: JSON loves ambiguity when it comes to numbers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Dates &amp;amp; Times = Pain&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Quick question: how do you represent a date in JSON?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ISO-8601 string?&lt;/li&gt;
&lt;li&gt;Unix timestamp?&lt;/li&gt;
&lt;li&gt;Custom "MM/dd/yyyy" string?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every system does it differently.&lt;br&gt;
And the worst part? The JSON spec doesn’t care — it has no native date type.&lt;/p&gt;

&lt;p&gt;I’ve spent hours debugging “off by one day” bugs because one service serialized dates in UTC, another in local time, and JSON didn’t give me any hints.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Lack of Schema = Surprises&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JSON is schema-less, which feels liberating at first… until your client app breaks because someone renamed a field.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "firstName": "John"
}
&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 plaintext"&gt;&lt;code&gt;
{
  "givenName": "John"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suddenly half your clients are broken — and you won’t even know until the bug reports roll in.&lt;/p&gt;

&lt;p&gt;With Protobuf or Avro, schemas are explicit and evolution is safer. With JSON, you’re relying on “be careful, don’t change stuff.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Hidden Security Risks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Attackers love JSON because parsers are everywhere and implementations vary. Some hidden costs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JSON bombs&lt;/strong&gt;: deeply nested objects that crash parsers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Injection attacks&lt;/strong&gt;: improperly escaped values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Large payload attacks&lt;/strong&gt;: abusing verbosity to exhaust memory.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your “simple JSON parser” is suddenly a new attack surface.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Tooling Fatigue&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ever tried to version JSON APIs? Or generate type-safe clients? Or validate large payloads?&lt;/p&gt;

&lt;p&gt;It’s possible — but clunky. You end up bolting on tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JSON Schema&lt;/li&gt;
&lt;li&gt;Code generators&lt;/li&gt;
&lt;li&gt;Manual validators&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Meanwhile, binary formats come with schemas built-in, and code generation “just works.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Industry Shift: Even LinkedIn Moved Away&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This isn’t just theory.&lt;/p&gt;

&lt;p&gt;LinkedIn famously moved away from JSON to Protobuf for their internal APIs. Why?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduced payload size&lt;/li&gt;
&lt;li&gt;Lower CPU cost for parsing&lt;/li&gt;
&lt;li&gt;Strong schema guarantees&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When a company operating at LinkedIn’s scale makes that shift, it’s worth paying attention.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, Should We Abandon JSON?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not at all. JSON still shines for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Human readability&lt;/strong&gt; (debugging is easy).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prototyping&lt;/strong&gt; (quick and dirty works).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interoperability&lt;/strong&gt; (every language speaks it).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But for high-scale APIs, JSON’s hidden costs add up fast.&lt;/p&gt;

&lt;p&gt;My personal rule of thumb:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JSON for external/public APIs where interoperability matters.&lt;/li&gt;
&lt;li&gt;Protobuf/Avro/MessagePack for internal APIs where efficiency matters.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Closing Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JSON is like pizza. 🍕&lt;br&gt;
Everybody loves it, it’s everywhere, and it works most of the time.&lt;/p&gt;

&lt;p&gt;But if you eat only pizza every day, eventually you’ll regret it.&lt;/p&gt;

&lt;p&gt;So next time you’re designing an API, ask yourself:&lt;br&gt;
👉 Do I really need JSON here, or is it time to reach for something faster, safer, leaner?&lt;/p&gt;

</description>
      <category>programming</category>
      <category>java</category>
      <category>json</category>
      <category>protobuf</category>
    </item>
  </channel>
</rss>
