jsonnet

data templating language that generates JSON

TLDR

Evaluate Jsonnet file
$ jsonnet [file.jsonnet]
Output to file
$ jsonnet [file.jsonnet] -o [output.json]
Evaluate with external variable
$ jsonnet --ext-str [name=value] [file.jsonnet]
Multi-file output
$ jsonnet -m [output_dir] [file.jsonnet]
Evaluate expression
$ jsonnet -e "[{a: 1, b: 2}]"
Format Jsonnet file
$ jsonnetfmt [file.jsonnet]

SYNOPSIS

jsonnet [options] file

DESCRIPTION

Jsonnet is a data templating language that generates JSON. It adds variables, conditionals, functions, and imports to JSON, making configuration files more maintainable.Jsonnet is used for generating Kubernetes manifests, Prometheus configurations, and other JSON/YAML configs. It evaluates to pure JSON.

PARAMETERS

-o file

Output file.
-m dir
Multi-file output directory.
-e code
Evaluate expression.
--ext-str name=value
External string variable.
--ext-code name=code
External code variable.
-J dir
Add library search path.
-S, --string
Output as string.
--tla-str name=value
Top-level argument string.

EXAMPLE

$ local person(name, age) = {
  name: name,
  age: age,
};

{
  people: [
    person("Alice", 30),
    person("Bob", 25),
  ]
}

INSTALL

sudo apt install jsonnet
sudo dnf install jsonnet
sudo apk add jsonnet
brew install jsonnet
nix profile install nixpkgs#jsonnet

CAVEATS

Output is always JSON (use for YAML via conversion). No side effects; pure functional. Libraries need -J path. Not for runtime config.

HISTORY

Jsonnet was developed at Google by Dave Cunningham around 2014. It addressed the need for DRY configuration in cloud infrastructure, gaining adoption in the Kubernetes ecosystem.

SEE ALSO

jq(1), yq(1), dhall(1)