Jsonnet is a domain specific configuration language that helps you define JSON data. Jsonnet lets you compute fragments of JSON within the structure, bringing the same benefit to structured data that templating languages bring to plain text. The example below illustrates a few features -- referring to another part of the structure, overriding object fields, and string operations.
Use Jsonnet to organize your JSON data, or to help your users organize the data they send to you. It is easy to integrate Jsonnet's library or commandline interpreter into existing systems that take JSON or YAML. Some example situations are application configuration (files in etc), build systems, package definitions, configuration management systems, and cloud deployment agents.
Jsonnet is ideal when you need to derive new data from existing data with subtle changes.
This was hinted at in the above example. A more comprehensive illustration is the simple build
configuration below. An object
CCompiler is defined, which is then specialized for GCC
and Clang. These are used to help construct an array of build targets.
Note the example mixins
Dbg that can be applied to add optimization flags. Mixins are the ultimate form of
inheritance, as they can be combined arbitrarily via the
+ operator. In simple cases,
they behave identically to conventional object-oriented languages like Java.
Try it out here
Jsonnet was designed and implemented at Google as a 20% project. The name Jsonnet is a portmanteau of JSON and sonnet, pronounced "jay sonnet". Jsonnet has been open-sourced under the Apache 2.0 license. Jsonnet is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.
Except as noted, this content is licensed under Creative Commons Attribution 2.5.