Dev Linux Docker Misc

7 Alternatives To JSON

3 min read 15 October 2022 On Dev

JavaScript Object Notation (JSON) is the most popular data serialization format these days 🙌

It is used in RESTful APIs, configuration files, for storing complex data in stringular format and much more. It's ability to be minified/compressed and human readability is what made it so popular.

JSON was initially specified in early 2000 and the first messages in JSON format were written in April of 2001. It has been accepted as an international standard in 2013.

{
	"name": "Vasanth Srivatsa",
    "twitter": "vsnthdev",
    "stack": ["JavaScript", "TypeScript", "Docker"],
    "portfolio": {
    	"link": "https://vsnth.dev"
	}
}
Sample data in JSON format.

1. JSON5 Data Interchange Format

JSON5 is a superset on top of JSON that adds additional functionality to the JSON spec. Double-quotes are not enforced and single-quotes can also be used to represent strings. Trailing commas are also possible, creating a more human readable version of JSON 👌

Although it definitely is a better implementation of JSON, support for JSON5 hasn't been implemented and hardened in a lot of programming languages yet except for JavaScript/TypeScript.

{
	name: 'Vasanth Srivatsa',
    twitter: 'vsnthdev',
    stack: ['JavaScript', 'TypeScript', 'Docker'],
    portfolio: {
    	link: 'https://vsnth.dev'
    }
}
Sample data in JSON5 format.

2. Binary JSON (BSON)

If human-readability isn't required, BSON offers ⚡ faster serialization (parsing) and deserializing (stringifying). BSON was created in 2009 to be used within MongoDB database.

It supports storing more data types than what JSON offers by default. But just like JSON5 support is lacking.

3. Yet Another Markup Language (YAML)

YAML is my favorite ✨ as it offers most readability with wide support and hardened libraries in different programming languages.

For user-interacting files containing small-to-medium amount of data like configuration files, YAML is perfect 👌 but JSON is faster when compared with YAML

name: 'Vasanth Srivatsa'
twitter: 'vsnthdev'
stack:
	- JavaScript
    - TypeScript
    - Docker
portfolio:
	link: https://vsnth.dev
Sample data in YAML format.

4. Tom's Obvious Markup Language (TOML)

Bringing a little more power while keeping focus on human-readability is TOML. Large & complex user-interactive data files, like config files of a large application are a perfect use-case for TOML.

Though it is slower compared to YAML & JSON & has slightly less support than YAML, TOML has 💪 powerful features like dot notation and support for more data types.

name = "Vasanth Srivatsa"
twitter = "vsnthdev"
stack = [ "JavaScript", "TypeScript", "Docker" ]

[portfolio]
link = "https://vsnth.dev"
Sample data in TOML format.

5. CoffeeScript Object Notation (CSON)

Mainly popularized by the Atom code editor, CSON is visually similar to YAML. Only difference between JSON and CSON is that curly brackets {} and square brackets [] are omitted in place of indentation.

With Atom editor coming close to end of life 😔 support for CSON is limited & uncertain. It also has very limited support outside of the JavaScript ecosystem.

name: 'Vasanth Srivatsa'
twitter: 'vsnthdev'
stack: [
	'JavaScript',
    'TypeScript',
    'Docker'
]
portfolio:
	link: 'https://vsnth.dev'
Sample data in CSON format.

6. Comma Seperated Values (CSV)

Out of all the above discussed data serialization formats, CSV is the most compact 🤏 and smallest. CSV format is more suited for long and tabular data than config files.

CSV parsers are available widely for almost all programming languages, with support for customization of the spec.

"name", "twitter", "stack", "portfolio__link"
"Vasanth Srivatsa", "vsnthdev", "JavaScript", "https://vsnth.dev"
"", "", "TypeScript", ""
"", "", "Docker", ""
Sample data in CSV format.

7. Extensible Markup Language (XML)

Introduced by W3C and published in 1998, it is the oldest data serialization format. Although it is powerful, it contains a lot of boilerplate code with repetitive tags wrapping each value 👎

It has wide support and has libraries in almost all programming languages.

<?xml version="1.0" encoding="UTF-8" ?>
<root>
    <name>Vasanth Srivatsa</name>
    <twitter>vsnthdev</twitter>
    <stack>JavaScript</stack>
    <stack>TypeScript</stack>
    <stack>Docker</stack>
    <portfolio>
        <link>https://vsnth.dev</link>
    </portfolio>
</root>
Sample data in XML format.

Conclusion

All of the 👆 above discussed data serialization formats have their pros & cons. These are the most popular formats, other notable mentions include ProtoBuf, MessagePack, Avro, Parquet and many more.

Thank you 😊