Rich_Morin

Rich_Morin

Data serialization formats

I’d like to start a discussion of data serialization formats, in the context of Elixir. The rest of this note is a combination of personal opinions and links to useful resources; feel free to jump in with your own clues, pointers, reactions, war stories, etc. (ducking…)

edn

edn (extensible data notation) is a subset of Clojure, extracted by Rich Hickey. edn has a rich set of built-in data types, most of which are a good match for Elixir. In addition, it has a mechanism for extending this set with custom data types.

However, because edn is closely tied to Clojure, Transit (see below) may be a better choice for interoperability. For details, see edn’s GitHub page and eden’s Hex page.

JSON

JSON is a subset of JavaScript, extracted by Douglas Crockford. Although JSON shines at interoperability and standardization, it has very limited (and JavaScript-specific) data types. So, for example, I wouldn’t recommend it for cases where one needs to retain and/or transmit specific data types.

JSON is also poorly suited for generating human-readable documents. It’s possible to include comments by using data elements, but this is a hack. And, although it’s quite possible to format JSON nicely, many programmers don’t make the effort. So, a lot of JSON “in the wild” is difficult for humans to read.

JSON-LD (JavaScript Object Notation for Linked Data) is a JSON-based method of encoding linked data. Thus, it can take the place of RDF-encoding formats such as N-Triples, RDF/XML, and Turtle.

TOML

TOML is an acronym for “Tom’s Obvious, Minimal Language”, referring to its creator, Tom Preston-Werner. Although TOML has very limited data types, it excels at generating human-readable documents.

Because the top of each “section” (i.e., sub-tree) can be encoded as a path, TOML works well for encoding deeply-nested hierarchical structures:

[a.b.c.d]
  e = 42

Transit

Transit is conceptually similar to edn, in that it is an extensible format with strong data type capabilities. However, it is considerably less tied to the Clojure language. Also, its “wire format” uses JSON or MessagePack. For details, see transit_elixir’s Hex page.

YAML

YAML (“YAML Ain’t Markup Language”) is generally well suited to writing by humans, although the need for multiple levels of indentation can become an issue for deeply nested trees. Also, the syntax definition is rather large, so reading some YAML documents can be difficult. Finally, because YAML “in the wild” isn’t well standardized, interoperability can be an issue.

Most Liked Responses

anuaralfetahe

anuaralfetahe

I had to serialize Elixir data structures before pushing to kafka topic I used :erlang.term_to_binary/1. The performance was good and I was easily able to deserialize the data on the consumer side(also running Elixir). This function is also useful when working with C nifs.

I noticed that I can push raw Elixir data structures to RabbitMQ without any serialization at all. Probably because it is written in Erlang.

When dealing with different technologies I’ve found JSON the easiest to work with because of the wide use and support it has.

D4no0

D4no0

What about asn.1? It is part of OTP and it is a fully fledged standardised implementation for binary encoding/decoding. If you never used it, protobufs is basically a reimplementation of a small set of features from asn.1 .

While very few people use this protocol, I think it has very big potential in systems where data consistency matters.

The only issue currently is that using it from elixir is very hard, it needs a wrapper with updated documentation.

cmo

cmo

I use MessagePack for internal communication over HTTP because it is smaller than JSON and that sort of thing floats my boat.

Where Next?

Popular in Wikis Top

OvermindDL1
It was stated at elixir-lang.org blocked in Russia · Issue #6172 · elixir-lang/elixir · GitHub that Mirrors of the primary Elixir website...
New
ibgib
Popular Elixir Packages List of popular Atom.io Elixir Packages. These can be installed via atom’s package center or a command line with ...
New
blackode
This is a wiki - anyone at Trust Level 1 or higher can help keep it updated. Elixir Pocket Syntax Uncommon Logical stuff of Elixir modul...
New
jdumont
Guide Using an iPad for web development can be easily split into two main parts: Setting up the iPad as a thin client Working in a remo...
New
shavit
To transcode the video there is FFMPEG. On Demand When a user uploads a video, the app renames and copy the file to a path, then call F...
New
nicbet
Introduction Now that the language is picking up support and maturing nicely, I’d like to start a collection of common and recurring Elix...
New
blackode
Hi and Hello Every Elixirian. After Learning the Elixir basics, I struck then. I have no idea of how to put my Elixir Knowledge in pract...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
AstonJ
Wonder if we can compile a list of learning resources, blog posts, talks, threads etc to help those who are just learning about Contexts....
New

Other popular topics Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New
hariharasudhan94
Lets say i have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => "XXX...
New

We're in Beta

About us Mission Statement