LinuxCommandLibrary

jsonnet

TLDR

Evaluate Jsonnet file

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

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),
  ]
}
copy

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), cue(1)

Copied to clipboard