Jsonnet
By Google
Jsonnet is a data templating language, created at Google, that extends JSON with variables, functions, conditionals, and object inheritance to generate JSON or YAML configuration programmatically. It compiles down to plain JSON, letting…
Definition
Jsonnet is a data templating language, created at Google, that extends JSON with variables, functions, conditionals, and object inheritance to generate JSON or YAML configuration programmatically. It compiles down to plain JSON, letting developers factor out repeated configuration into reusable templates while still producing standard, tool-agnostic output. Jsonnet is used mainly for generating complex Kubernetes manifests and other structured configuration where hand-written JSON or YAML would involve significant duplication.
Overview
Jsonnet was created at Google to address a problem common to large configuration systems: JSON and YAML are excellent as static data formats but have no native way to express reuse, meaning teams end up copy-pasting near-identical blocks of configuration across many files and environments, with all the drift and maintenance burden that implies. Jsonnet keeps the familiar JSON object-and-array shape while adding a programming layer on top specifically for generating that JSON. Mechanically, Jsonnet files look like JSON with extensions: they support local variable bindings, functions that take parameters and return values, string and arithmetic operations, and an object model with inheritance through the `+` operator, which lets one object extend or override fields from another. A Jsonnet program does not produce configuration directly at runtime; instead, it is evaluated once by the `jsonnet` compiler to render fully resolved, plain JSON output that downstream tools like Kubernetes can consume without needing any Jsonnet-aware tooling themselves. Jsonnet differs from HCL, Terraform's configuration language, in that HCL is purpose-built around infrastructure resource declarations with built-in provider and state semantics, whereas Jsonnet is a general data templating language agnostic to what the generated JSON represents. It also differs from templating approaches like Helm's Go-template-based YAML templating for Kubernetes, offering a more structured, expression-based approach to reuse rather than text-substitution templating, which some teams find less error-prone for deeply nested configuration. In practice, Jsonnet is used heavily to generate Kubernetes manifests across many environments and services, where a base template captures common configuration and environment-specific overlays adjust only what differs, avoiding the duplication that plain YAML manifests would require. It also appears in other infrastructure and application configuration contexts where JSON or YAML output needs to be assembled programmatically from shared building blocks, and tools like the Kubernetes-specific ksonnet library (now largely superseded) were built around it. Jsonnet's functional, expression-based syntax has a learning curve for engineers used to plain YAML or JSON, and debugging deeply nested object inheritance and overrides can be harder to trace than with straightforward templating. Its ecosystem is also narrower than more general infrastructure-as-code tools. Teams adopt Jsonnet specifically when configuration duplication across many similar environments or services has become a real maintenance burden, and stick with plain YAML or JSON when configurations are simple enough that added tooling would not pay for itself. Some teams also evaluate newer alternatives like CUE before settling on Jsonnet, weighing each tool's specific balance of expressiveness, validation features, and learning curve against their own configuration complexity.
Key Features
- Extends JSON syntax with variables, functions, and conditionals
- Object inheritance and field overriding through the `+` operator
- Compiles to plain, tool-agnostic JSON or YAML output
- Created at Google specifically for large-scale configuration reuse
- Supports imports for splitting configuration across multiple files
- Widely used for generating Kubernetes manifests across environments
- Deterministic, pure functional evaluation with no side effects
- Standard library of built-in functions for string and data manipulation