JSON alternatives for data | Indepth | JSON Editor Online (2024)

JSON is one of the most mainstream, universal data formats out there. It is loved because of its simplicity and because it is human-readable, making it easy to use. It is also criticized because it is verbose, it doesn’t support comments, it has limited data types, and it doesn’t enforce a data structure using a schema.

So, is there anything better than JSON? Before we can answer that question, we have to understand that JSON is used in two very different cases. In this second article of a series of two we discuss JSON alternatives for data.

  1. JSON alternatives for configuration files (click here to read)
  2. JSON alternatives for data transfer and storage (this article)

These two categories come with different needs. For example, for configuration files it is important that data format is easy to read and supports comments for documentation. For data transfer and storage, it is important that the data is concise and can be serialized and de-serialized in a fast way.

We’ll first discuss how well JSON itself does for data, and then discuss a number of alternatives.

JSON

When to use: in most cases JSON is a great choice for data.

Website: https://www.json.org/

JSON is excellent for data exchange and storage. It hits a sweet spot between being an extremely simple format and being powerful and flexible enough to store any kind of structure. Because it is a text based format, it is easy to work with. Today it is one of the most ubiquitous data formats, which is an extra reason to choose JSON. In many cases, choosing JSON is simply the best choice, but there are interesting alternatives that can be a good fit depending on your use case.

Some of the main criticisms of JSON for data are that it is verbose because it repeats field names for every object and requires double quotes around every key and string. It doesn’t enforce a data structure (though you can specify a JSON schema). And it has a limited number of data types, for example it has no built-in support for dates.

Here is an example of a JSON array containing a set of objects:

[ { "name": "Chris", "age": 23, "city": "New York" }, { "name": "Emily", "age": 19, "city": "Atlanta" }, { "name": "Joe", "age": 32, "city": "New York" }, { "name": "Kevin", "age": 19, "city": "Atlanta" }, { "name": "Michelle", "age": 27, "city": "Los Angeles" }, { "name": "Robert", "age": 45, "city": "Manhattan" }, { "name": "Sarah", "age": 31, "city": "New York" }]

CSV

When to use: CSV is perfect for tabular data.

Website: https://en.wikipedia.org/wiki/Comma-separated_values

The CSV data format is even simpler and older than JSON. CSV stands for “comma separated value”, and it’s great for tabular data. It is a popular standard since the format is so simple, universal, and easy to read and parse. It has a limited use case: tabular data. The data format is very concise.

You can read a more in depth comparison in the article “JSON vs CSV: what is the difference and what should I use?“.

The above JSON data example can be represented in CSV as follows:

name,age,cityChris,23,New YorkEmily,19,AtlantaJoe,32,New YorkKevin,19,AtlantaMichelle,27,Los AngelesRobert,45,ManhattanSarah,31,New York

Note that CSV does not really support nested structures, it is possible to encode nesting in field names, like "user.address.city", where the dots mean a nested object.

BSON

When to use: BSON is perfect for MongoDB data, requiring advanced data types and fast scanning.

Website: https://www.mongodb.com/basics/bson

BSON is a binary data format that was developed for MongoDB. It was developed to support more advanced data types like Date, 64 bit Long, Regex, and more. It is optimized for efficient storage and scanning.

A downside of BSON is that it is more complex and less universal than JSON. Since it is a binary format, you can’t inspect a BSON file with a simple text editor, but you need special tooling. BSON is not necessarily faster or smaller than JSON (especially if you use JSON in combination with zip). If you intend to use BSON, it is important to first do an experiment to see how BSON performs on your data, to weigh the pros and cons.

Here is a BSON example which encodes the JSON document {"hello":"world"}

\x16\x00\x00\x00 // total document size\x02 // 0x02 = type Stringhello\x00 // field name\x06\x00\x00\x00world\x00 // field value\x00 // 0x00 = type EOO ('end of object')

Protocol Buffers and FlatBuffers

When to use: for strongly typed, high performance communication between servers.

Website: https://protobuf.dev/ and https://flatbuffers.dev/

Both Protocol Buffers and FlatBuffers offer a solution for serializing structured data in a binary form. They allow you to define a strongly typed schema for your data first, and then generate optimized code for the language that you’re working in (C++, C#, Go, Java, Kotlin, Python, and more) to read and write data. It is considerably faster than JSON serialization/deserialization, and can be used for server to server communication.

It is important to realize that the serialized data is not directly readable: you need the corresponding proto definition file and tooling to deserialize and read it. And this comes with a compile-step to generate the classes allowing to do this.

Here an example of a proto definition:

message Person { optional string name = 1; optional int32 id = 2; optional string email = 3;}

With this definition, you can generate a class for usage in your programming language, for example sending data from a Java application:

// Java codePerson john = Person.newBuilder() .setId(1234) .setName("John Doe") .setEmail("[email protected]") .build();output = new FileOutputStream(args[0]);john.writeTo(output);

And then receiving data in a C++ application:

// C++ codePerson john;fstream input(argv[1], ios::in | ios::binary);john.ParseFromIstream(&input);id = john.id();name = john.name();email = john.email();

So what is the difference between Protocol Buffers and FlatBuffers? It is explained as follows on the site of FlatBuffers:

Protocol Buffers is indeed relatively similar to FlatBuffers, with the primary difference being that FlatBuffers does not need a parsing/ unpacking step to a secondary representation before you can access data, often coupled with per-object memory allocation. The code is an order of magnitude bigger, too. Protocol Buffers has no optional text import/export.

Internet Object

When to use: not yet, it is a proof of concept but looks promising.

Website: https://docs.internetobject.org

Internet Object is an interesting concept. It describes itself as a “thin, schema-first and robust data-interchange object format for Internet”. It looks like the best of CSV and JSON combined. It is a plain text format. It introduces a header where you can define the data structure as a schema, making it a format as compact as CSV, but not limited to tabular data. It supports rich data structures like nested objects and arrays like JSON. It keeps the number of data types limited, in the spirit of JSON.

Here is an Internet Object example:

# The address definition~ $address: {street:string, zip:{string, maxLength:5}, city:string}## The person definition~ $schema: { name:string, # The person name age:int, # The person age homeAddress?: $address, # The home address}---# Records~ Chris, 23, {Park Avenue, 50010, New York}~ Emily, 19, {2nd St, 22018, Atlanta}~ Joe, 32, {Wall Street, 4089, New York}~ Kevin, 19, {Balerma St, 22018, Atlanta}~ Michelle, 27, {Broadway, 3019, Los Angeles}~ Robert, 45, {Franklin Ave, 44200, Brooklyn}~ Sarah, 31, {Fifth avenue, 10027, New York}

XML

When to use: in general, don’t use XML, JSON is almost always the better choice.

Website: https://www.xml.com/

It is good to mention XML too as an alternative to JSON for data. JSON was developed (or better: discovered by Douglas Crockford) as an alternative for XML. JSON is a much simpler format, is faster, is much more concise, and is less ambiguous. JSON is in most cases the better choice over XML. XML though has support for comments and built-in options for providing a schema alongside the data, and it is similar to HTML.

Here an XML example:

<?xml version="1.0"?> <ProductList title="Electronics"> <Product> <Name>Smartphone X</Name> <Description>Fast and with a great battery life.</Description> <Cost>$395.00</Cost> <Shipping>$8.95</Shipping> </Product> <Product> <Name>Product Two</Name> ... </Product> <Product> <Name>Smartphone Y</Name> <Description>Good value for your money.</Description> <Cost>$199.00</Cost> <Shipping>$8.95</Shipping> </Product> ... </ProductList>

Conclusion about JSON alternatives for data

In general, the simplest solutions are the most robust and ubiquitous. Both JSON and CSV are popular because of their simplicity. It makes them easy to use in any environment. CSV is more limited since it only supports tabular data. But on the other hand, it is a more concise format than JSON.

There is one interesting concept, Internet Object, which combines the best of CSV and JSON in a new data format. This is interesting to keep an eye on.

There are binary formats such as BSON, Protocol Buffers, and FlatBuffers, which may offer better performance and offer more advanced data types. This comes at a cost though: binary formats are less easy to use and inspect, and requires more advanced tooling and knowledge.

JSON alternatives for data | Indepth | JSON Editor Online (2024)
Top Articles
French - the language of love
iPad generations: all iPad models
Kostner Wingback Bed
How to change your Android phone's default Google account
Hawkeye 2021 123Movies
San Diego Terminal 2 Parking Promo Code
Bloxburg Image Ids
Craigslist - Pets for Sale or Adoption in Zeeland, MI
Oppenheimer & Co. Inc. Buys Shares of 798,472 AST SpaceMobile, Inc. (NASDAQ:ASTS)
Lenscrafters Huebner Oaks
Available Training - Acadis® Portal
Wilmot Science Training Program for Deaf High School Students Expands Across the U.S.
Nashville Predators Wiki
Craigslist Free Stuff Greensboro Nc
Jellyfin Ps5
Webcentral Cuny
Encore Atlanta Cheer Competition
Ezel Detailing
Mythical Escapee Of Crete
Spiritual Meaning Of Snake Tattoo: Healing And Rebirth!
14 Top-Rated Attractions & Things to Do in Medford, OR
Jackass Golf Cart Gif
Orange Park Dog Racing Results
The Fabelmans Showtimes Near Baton Rouge
Himekishi Ga Classmate Raw
Taylored Services Hardeeville Sc
Meowiarty Puzzle
Bad Business Private Server Commands
Craigs List Tallahassee
Swimgs Yuzzle Wuzzle Yups Wits Sadie Plant Tune 3 Tabs Winnie The Pooh Halloween Bob The Builder Christmas Autumns Cow Dog Pig Tim Cook’s Birthday Buff Work It Out Wombats Pineview Playtime Chronicles Day Of The Dead The Alpha Baa Baa Twinkle
Roadtoutopiasweepstakes.con
Pch Sunken Treasures
Colorado Parks And Wildlife Reissue List
Ket2 Schedule
Why Holly Gibney Is One of TV's Best Protagonists
Tds Wifi Outage
Express Employment Sign In
Craigslist Food And Beverage Jobs Chicago
21 Alive Weather Team
2017 Ford F550 Rear Axle Nut Torque Spec
Craigslist Binghamton Cars And Trucks By Owner
Go Nutrients Intestinal Edge Reviews
Searsport Maine Tide Chart
Xre 00251
Greatpeople.me Login Schedule
Myra's Floral Princeton Wv
Joy Taylor Nip Slip
10 Best Tips To Implement Successful App Store Optimization in 2024
Bama Rush Is Back! Here Are the 15 Most Outrageous Sorority Houses on the Row
Diesel Technician/Mechanic III - Entry Level - transportation - job employment - craigslist
Coldestuknow
Latest Posts
Article information

Author: Sen. Ignacio Ratke

Last Updated:

Views: 5925

Rating: 4.6 / 5 (56 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.