Data Format Comparison

Serialize the same data as JSON, XML and real Protocol Buffers in your browser, then compare byte size and encode and decode times over repeated runs.

The interactive tool loads here when JavaScript runs.

About this tool

What is Data Format Comparison?

Data Format Comparison serializes the same dataset as JSON and XML in your browser and compares their size and serialization and parse times alongside real Protocol Buffers encoding. You can use a small sample, generate a 100-user dataset, or paste your own JSON.

All three formats are encoded and decoded for the selected number of iterations (1 to 100). Timings use your chosen average or an interpolated P50, P95 or P99 percentile. Protocol Buffers use a generic JSON-value schema that preserves arbitrary custom JSON, not an optimized application schema, and XML timing includes building and reading a DOM.

That makes the results a fair comparison of these three implementations on your data in your browser. They are not universal rankings: a hand-written .proto schema is usually smaller than the generic one, and server-side parsers have different speeds.

  • Real JSON and XML serialization of your data in the browser
  • Actual Protocol Buffers bytes via protobufjs, using a generic JSON-value schema
  • Size and timing comparison with fastest and smallest summary
  • Average, P50, P95 and P99 over 1 to 100 iterations
  • Sample output for each format; runs locally
Read the guide: JSON vs XML vs Protocol Buffers: Size, Speed and Trade-offs

Updated

How to use Data Format Comparison

  1. Click Use Small Dataset or Generate Large Dataset, or paste your own JSON into the Current Test Data box.
  2. Choose the number of Iterations and a Statistical Metric (Average, P50, P95 or P99).
  3. Click Run Comparison and compare the size and timing results, including which format is fastest and smallest.
  4. Open the JSON, XML and Protocol Buffers tabs to see sample output.

Worked example

One small record, three encodings

Input

{"id": 42, "name": "Ada", "active": true}

Output

JSON 41 bytes as written; XML <user><id>42</id><name>Ada</name><active>true</active></user> 61 bytes; a dedicated protobuf schema 9 bytes

The protobuf figure assumes a schema with three numbered fields. This page's generic schema must also describe the structure, so it reports more than 9 bytes, which is why your own .proto matters.

Background and insight

XML became a W3C Recommendation in 1998 and dominated enterprise integration and SOAP web services through the 2000s. JSON, popularized by Douglas Crockford in the early 2000s, won the web API world because it maps directly onto the objects and arrays of JavaScript and most other languages. Protocol Buffers were developed inside Google and open-sourced in 2008; they are the default payload for gRPC.

The size differences come from what each format repeats. XML repeats every tag name twice, opening and closing. JSON repeats every key once per object. Protobuf replaces field names with small numeric tags defined in a .proto schema and encodes integers as variable-length bytes, which is why it is usually much smaller.

Small differences in a single run of a browser benchmark are mostly noise, because JIT warm-up and garbage collection affect timings. Use more iterations and look at the median rather than one run. Real decisions about formats are usually driven by interoperability, schema evolution and tooling more than by a few milliseconds of parse time.

Common use cases

  • Explaining format trade-offs

    Show a team why XML payloads are larger than JSON for the same data.

  • Estimating payload size

    Paste a representative API response to see its JSON, XML and Protobuf size.

  • Learning serialization

    See the same records rendered in each format side by side.

  • Sanity-checking a migration

    Get a rough feel for whether moving an endpoint to a binary format is worth the tooling cost.

Tips and limitations

  • Run 25 or more iterations and use P50. A single run is dominated by JIT warm-up.
  • Compare gzip sizes too before deciding. Compression narrows the gap between text and binary formats a lot.
  • Browser numbers say little about server-side throughput, where parsers such as simdjson or a compiled protobuf library behave differently.
  • Paste a real response from your API rather than the sample. Field names, nesting and string lengths change the ratios.
  • Use the Protobuf tools page to write and test a real .proto schema for your data.

Sources and further reading

  1. Extensible Markup Language (XML) 1.0 (Fifth Edition), W3C. The XML Recommendation, first published in 1998
  2. RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format, IETF
  3. Protocol Buffers: Encoding, Google. How field numbers and varints keep protobuf messages small
  4. Introduction to gRPC, gRPC Authors. Protocol Buffers as gRPC's default message format

Frequently asked questions

Are the Protocol Buffers results real measurements?

Yes. Encoding and decoding use protobufjs, and the reported size is the actual byte length. A generic JSON-value schema preserves your custom data, which can be larger than an optimized domain-specific schema with numbered fields. Benchmark your production schema separately before choosing a format.

Why is XML larger than JSON for the same data?

XML writes every element name twice, in the opening and closing tag, and often adds attributes and namespaces. JSON writes each key once and uses single characters for structure. For a record like {"id": 42, "name": "Ada", "active": true}, the XML equivalent is about 50% larger.

Is JSON always slower to parse than Protobuf?

Usually, but not always. Browser JSON.parse is native code and very fast, while protobufjs runs in JavaScript, so for small payloads JSON can win in this test. Compiled protobuf libraries on servers are typically faster than JSON. Benchmark with your own data and runtime.

Does compression change the JSON vs Protobuf size comparison?

Yes. gzip or Brotli shrink repetitive text formats a lot, because repeated keys and tags compress well, which narrows the size gap between JSON, XML and binary formats. Compare compressed sizes, since that is what actually crosses the network.

Which statistical metric should I pick for the benchmark?

Use P50 (the median) for a typical run, since it ignores occasional slow runs caused by garbage collection. P95 and P99 show tail latency, which matters for user-facing requests. The average is easy to skew with one outlier, so treat it with care.

Is there an in-depth guide to Data Format Comparison?

Yes. “JSON vs XML vs Protocol Buffers: Size, Speed and Trade-offs” covers the background, how it works, common pitfalls and worked examples. Read the full guide.