Skip to content

Releases: google/jsonnet

v0.8.1

24 Sep 19:26
Compare
Choose a tag to compare
v0.8.1 Pre-release
Pre-release

Jsonnet v0.8.1 release notes

There are 2 major things in this release:

Asserts

The biggest change in this release is the addition of the assert construct. This is backwards-compatible except if you were using 'assert' as an identifier, in which case you'll have to rename it (or use quotes "assert": in the case of a field name).

Assert expressions

assert e1 : e2; e3

Is simply desugared to

if e1 then e3 else error e2

And the : e2 is optional like in Python and Java (except Python uses a comma instead of a colon).

Object assertions (invariants)

It is also possible to put asserts into objects:

local Base = {
    assert self.x <= self.y : "%d greater than %d" % [self.x, self.y],
    x: 1,
    y: 2,
};

These are preserved over inheritance and follow the usual late binding semantics.

Base { x: 3 }  // Raises an error.
Base { x: 3, y: 4 }  // Ok.

This can be useful for enumerations:

local Base = {
    assert std.setMember(self.animal, self.availableAnimals)
           : "%s is not a valid animal" % self.animal,
    animal: error "You must select an animal",
    availableAnimals: ["CAT", "DOG"],
};
Base { animal: "FISH" }  // Raises an error.
Base { animal: "FISH", availableAnimals+: ["FISH"] }  // Ok.

If you want to constrain the base object so the animals cannot be extended, you can do:

local Base = {
    local available_animals = ["CAT", "DOG"],
    assert std.setMember(self.animal, available_animals)
           : "%s is not a valid animal" % self.animal,
    animal: error "You must select an animal",
};

Preventing override of fields

Finally, using this mechanism you can lock down a template so that users can only override the "inputs", not the "outputs". For example imagine building bash scripts as part of a workflow framework:

local Template = {
    user:: error "Must set user",
    command:: error "Must set command",
    outputFile:: "out.log",

    local template = self,
    local output = {
        bash: "sudo %(user)s \"%(command)s\" > %(outputFile)s" % template,
    },
    bash: output.bash,
    assert self == output : "You may not override this template's output."
};
// User code:
Template {user: "myname", command: "ls", bash+:"; echo hi"}

This would produce an error because the assertion prevents the user from adding stuff onto the end of the bash command.

Removal of super as a construct in its own right

Early in development we decided to avoid restrictions in the language to see where this would lead us. Two such cases led to implementation complexity and we were tempted to remove them, but we were not sure if they would be useful. One case was mixins, which turned out to be enormously useful in many cases. The other case was the ability to do super by itself, not just in the context of super.f or super[e]. The semantics of this were tricky to define in the case of extending super, or extending super with itself (although we did so, and the rules are on the website)! It also makes the interpreter and object model harder to implement. To the best of our knowledge, there is not one single person using super in this fashion, so we have now restricted it to just super.f and super[e] as done in other languages.

v0.8.0

20 Aug 19:27
Compare
Choose a tag to compare
v0.8.0 Pre-release
Pre-release

This release has a few more examples.

The main new feature is the ability to specify multiline strings more easily, i.e. instead of the ugly

{
    foo: "#!/bin/bash
echo \"Hello world!\"",
}

or the bureaucratic

{
    foo: std.lines([
        "#!/bin/bash"
        "echo \"Hello world!\"",
    ])
}

you can now do the following, which is similar to the YAML "block style" construct.

{
    foo: |||
        #!/bin/bash
        echo "Hello world!"
    |||,
}

The indentation is stripped.

Note that this is just a string literal, so it can be combined with % to do string templating:

{
    foo: |||
        #!/bin/bash
        echo "Hello %(greetable_entity)s!"
    ||| % {
        greetable_entity: "world"
    },
}

v0.7.9

04 Aug 21:33
Compare
Choose a tag to compare
v0.7.9 Pre-release
Pre-release

This release has the following changes since v0.7.6 (intermediate versions exist on PyPy but not Github):

  • Add std.setMember
  • Various bug fixes related to transitive imports not being correctly resolved
  • Addition of import_callback to Python bindings

v0.7.6

03 Jun 01:30
Compare
Choose a tag to compare
v0.7.6 Pre-release
Pre-release

This release has the following changes:

  • Various minor bug fixes.
  • Replace garbage collector with one that can handle larger heaps.
  • Add tailstrict function call annotation for O(1) memory consumption in tail-recursive functions.
  • Added sort, uniq, and set functions to stdlib
  • Python extension is now built with setup.py

v0.7.5

01 May 05:18
Compare
Choose a tag to compare
v0.7.5 Pre-release
Pre-release

Some minor fixes to the manifestation of large numbers, as well as new errors when computing NaN/Inf during execution.

v0.7.0-beta

11 Mar 20:29
Compare
Choose a tag to compare
v0.7.0-beta Pre-release
Pre-release

This release should be backwards-compatible.

New features:
Null field names now omitted from object #10
std.base64 functions #28
Trapping import to implement virtual filesystems #8
Now possible to write Jsonnet libraries, importable via a search path #18
Comments can now start with # (as well as the C++ and C styles /**/ and //). This allows #!/usr/bin/jsonnet #27

v0.6.0-beta

14 Nov 02:09
Compare
Choose a tag to compare
v0.6.0-beta Pre-release
Pre-release

Three minor backwards-incompatible changes:

  1. std.env is renamed to std.extVar. This is because environment variables are not the only way to get now-called 'external' variables into Jsonnet, you can also pass them explicitly on the command line (or via the library API).

  2. The hidden status of fields defined with : is now preserved over inheritance instead of being reset by the base class. This means subobjects overriding fields from superobjects do not have to worry about whether those fields should appear in the output or not.

  3. A new keyword tailcall is reserved for future use.

There are a number of enhancements to the standard library and interpreter, including the ability to generate multiple JSON files from a single authoritative Jsonnet configuration.

v0.5.0-beta

26 Aug 18:07
Compare
Choose a tag to compare
v0.5.0-beta Pre-release
Pre-release

First version-numbered release of Jsonnet.