Google recently introduced a new open-source configuration language for generating JSON known as Jsonnet.
Google quietly released Jsonnet a few months ago as a programming language for specifying data. The Jsonnet Website calls Jsonnet a data templating language.
Jsonnet doesn’t just generate JSON: It is also an extension of JSON, said Dave Cunningham, a member of Google’s New York Technical Infrastructure team, in a blog post about the new language.
“By adding new constructs between the gaps of existing JSON syntax, Jsonnet adds useful features without breaking backwards compatibility,” Cunningham said. “Any valid JSON is also a valid Jsonnet program that simply emits that JSON unchanged, and existing systems that consume JSON (or its cousin YAML) can be easily modified to accept data in the full Jsonnet language. As such, Jsonnet is an example of a templating language, but one specifically designed for JSON data and less error-prone than other techniques.”
Cunningham also noted that many systems can be configured with JSON, but writing it by hand can be difficult. “Jsonnet is packed with useful data-specification features that expand into JSON for other systems to act upon,” he said.
JSON, or JavaScript Object Notation, is an open standard format that uses human-readable text to transmit data objects consisting of attribute-value pairs. It is used primarily to transmit data between a server and Web application, as an alternative to XML.
Jsonnet is a domain-specific configuration language that helps users define JSON data. It enables users to compute fragments of JSON within the structure, bringing the same benefit to structured data that templating languages bring to plain text.
Cunningham said Jsonnet is a portmanteau of JSON and sonnet. The team selected that name to convey that data expressed in Jsonnet is easier to write and maintain “because it is more elegant and concise, like a poem,” he said. “This is not just due to syntactic niceties like comments and permissive quotes/commas, but because Jsonnet has all the modern multi-paradigm programming language conveniences needed to manage complexity. One key benefit is the ability to use Jsonnet’s mixin and import features to write modular configuration template libraries, allowing the creation of domain-specific configuration languages for particular applications.”
Jsonnet was innovatively conceived using both academic techniques and Google’s own experience implementing production languages, according to Cunningham.
“Unlike most configuration languages, Jsonnet has a full operational semantics, ensuring matching behavior from third-party implementations as well as mathematical analysis,” he said. “It is a very small and carefully chosen extension to JSON that can express both object-oriented and declarative styles.”
Cunningham said that more importantly, unlike regular programming languages, Jsonnet is hermetic, which means its evaluation “is independent of any implicit environmental factors, ensuring that high level configuration will resolve to the same thing every time.”
Jsonnet is available as a library with C and Python bindings, and also as a command line utility.