Over the past year I’ve been creating a templating language called Eucalypt. I have been building it because I wanted it, I had a pretty clear idea what it should be like and that it really should exist and yet I hadn’t found it despite some searching around.

Inevitably, I discovered last week the something very like it (Jsonnet) not only exists, but is created and maintained by Google and has been around since 2014, so how it managed to slip under my radar I have no idea.

In fact I find it quite scary how similar they are given that I was entirely oblivious to the existence of Jsonnet. It only goes to show, in my eyes, how obvious the idea is and therefore how frustrating that it’s not adopted more generally.

In fact, the first example on Jsonnet’s home page, example1.jsonnet:

// Edit me!
  person1: {
	name: "Alice",
	welcome: "Hello " + self.name + "!",
  person2: self.person1 { name: "Bob" },

is very close to being valid Eucalypt. The main differences here:

  • the comment syntax is different (though both support #)
  • self. is unnecessary (and illegal) in Eucalypt, the names are in scope
  • top-level braces are unnecessary (and illegal) in Eucalypt
  • the string concatentation should use interpolation in Eucalypt
  • the commas are optional (but legal) in Eucalypt

So idiomatic Eucalypt would be:

# Edit me!
person1: {
  name: "Alice"
  welcome: "Hello {name}!"
person2: person1 { name: "Bob" }

It’s quite striking to me that syntactically, the means of merging objects together (person1 { name: "Bob" }) is exactly the same in each even though it is achieved by completely different means.

In Eucalypt it is the application of a block as a function to another block. (Via block catenation, for an intro see here.)

In Jsonnet it is the elision of an implicit ‘+’ operator between objects which represents a form of inheritance.

The use cases of the projects overlap very closely. Jsonnet can generate JSON for Kubernetes, Terraform and CloudFormation in the way Eucalypt can and both intend to be very general data templating languages.

There are other striking similarities in what the two languages have implemented, and in some cases what I was planning for Eucalypt and what Jsonnet has already delivered. They clearly share some influences as evidenced by their terminology (they both “desugar” to a “core” syntax) and they both operate by lazy evaluation.

The language philosophy seems very different. Jsonnet touts “object-orientation” whereas Eucalypt’s philosophy is strictly and purely functional, the affinities with OO being those that emerge organically. Eucalypt emphasises functional composition pipelines where Jsonnet emphasises object inheritance.

Non-technical differences between the projects are obvious. One, Jsonnet, is mature and well-adopted. The other, Eucalypt, is immature, unknown and, frankly, experimental.

Syntactically, Jsonnet has more natural affinity with JSON, Eucalypt can be embedded in YAML and it’s own syntax has more influence from YAML and Clojure.

I need to study Jsonnet in more detail to do a comprehensive analysis. My initial reaction is that the future direction of Eucalypt takes it on a course sufficiently distant from Jsonnet to justify some continuing effort. In any case there’s much to learn from the Jsonnet design and its standard library and I’m relieved that there is a decent toolset out there where I thought it was so conspicuously absent.