Jsonnet

Latest version: v0.20.0

Safety actively analyzes 723144 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 5 of 7

0.8.8

This release merely fixes some problems with the Bazel build files in the previous release. As such, there is no need for a corresponding Python release.

0.8.7

Firstly, Jsonnet users should be aware of a tiny non-backwards-compatible change: It is no longer possible to put spaces or comments between the characters of each of the following operators :: +: ::: and +::: . The fact this was ever possible was an accident of implementation. In fact, we expect no-one was actually writing code like { x: /*foo */: 3 }.

With that out of the way, let's talk about the many new features this release:

The major announcement is the Jsonnet reformatter, which is in many ways like the Go reformatter, including the way it is invoked:


jsonnet fmt foo.jsonnet


(See --help for more details.)

This tool will clean up whitespace, re-indent, and use syntax sugars where possible. It can control the way strings are quoted and the comment style. However it will not (yet) break or join lines. It is quite extensible so please submit issues for more things you think it should fix. An obvious candidate is alphabetic re-ordering of imports!

One thing for which it's very useful is the process of bootstrapping unformatted JSON code into beautiful Jsonnet. To do this, use a standard JSON reformatter like json_pp to line-break the JSON how you want. Then run jsonnet fmt on it to strip the quotes from field names where possible and put commas on the end of lines. That takes care of the most boring aspects of refactoring JSON into Jsonnet!

Another new feature is to add Python style array slicing. This is the ability to do


local arr = ['it', 'was', 'the', 'best', 'of', 'times'];
assert arr[2:4] == ['the', 'best'];
assert arr[1::2] == ['was', 'best', 'times'];
true


This is designed to be compatible with Python, except the ability to use negative numbers to refer to elements relative to the far end of the array. The rationale: We'd rather have an explicit error to catch broken index arithmetic, and you can always use std.length() when you (rarely) need to refer to the last element of an array.

Did you notice the last example used ' for string literals instead of the " as prescribed by JSON? This new kind of string literal is useful in cases when you want to embed " in your string without escaping. It also has a bit less visual clutter.

Another innovation is --yaml-stream, which was implemented primarily for easy output into kubectl (from the Kubernetes project). The idea is that the Jsonnet script manifests into a JSON array, and this is rendered as a "YAML stream". For more context see yaml.org.


$ jsonnet --yaml-stream -e '[{ animal: "dog", sound: "woof" }, { animal: "cat", sound: "meow" }]'
---
{
"animal": "dog",
"sound": "woof"
}
---
{
"animal": "cat",
"sound": "meow"
}
...


The final new feature: We now have JSON merge patch support (RFC7396) in the standard library.

0.8.6

Aside from minor improvements and bug fixes, this release has one change to the language that is not compatible with previous versions.

Some users pointed out that import "foo" + bar had surprising behavior, because it looks like it will compute the name of the import, but in actual fact it is parsed as (import "foo") + bar, which converts the imported Jsonnet file to a string, then appends bar to it. In order to avoid that confusion, we've make the parentheses mandatory in those cases.

The vast majority of imports, which are unambiguous, are not affected. For example:

local foo = import "foo";

This release also fixes the compilation of Jsonnet during pip install.

0.8.5

Yet another release needed to fix the Python build.
This release also includes the restrictions on super that should have been in v0.8.1 but the change got lost in the gh-pages branch.

0.8.4

Fix the Python release (again).

0.8.3

The last release was broken on Python so this fixes that. It also fixes a bug with decoding high unicode codepoints.

Page 5 of 7

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.