---
layout: default
---
Jsonnet Online Demo
This JavaScript build of Jsonnet runs in your browser.
There is no filesystem, so import
will not find any files. In most browsers, the textboxes can
be made larger by dragging their bottom right corner.
Don't know what to write? The following links replace the above Jsonnet with various examples.
-
Build script example
{% include examples/build_example.jsonnet %}
-
Alice & Bob
{% include examples/landingpage.jsonnet %}
-
Tutorial code: bar_menu.1.jsonnet
{% include examples/bar_menu.1.jsonnet %}
-
Tutorial code: bar_menu.2.jsonnet
{% include examples/bar_menu.2.jsonnet %}
-
Tutorial code: bar_menu.3.jsonnet
{% include examples/bar_menu.3.jsonnet %}
-
Tutorial code: example_operators.jsonnet
{% include examples/example_operators.jsonnet %}
-
Tutorial code: bar_menu.5.jsonnet
{% include examples/bar_menu.5.jsonnet %}
-
Tutorial code: bar_menu.6.jsonnet (with inlined import)
local ImportedMartinis = {
"Vodka Martini": {
ingredients: [
{ kind: "Vodka", qty: 2 },
{ kind: "Dry White Vermouth", qty: 1 },
],
garnish: "Olive",
served: "Straight Up",
},
Cosmopolitan: {
ingredients: [
{ kind: "Vodka", qty: 2 },
{ kind: "Triple Sec", qty: 0.5 },
{ kind: "Cranberry Juice", qty: 0.75 },
{ kind: "Lime Juice", qty: 0.5 },
],
garnish: "Orange Peel",
served: "Straight Up",
},
};
// bar_menu.6.jsonnet
{
cocktails: ImportedMartinis + {
Manhattan: {
ingredients: [
{ kind: "Rye", qty: 2.5 },
{ kind: "Sweet Red Vermouth", qty: 1 },
{ kind: "Angostura", qty: "dash" },
],
garnish: "Maraschino Cherry",
served: "Straight Up",
},
Cosmopolitan: {
ingredients: [
{ kind: "Vodka", qty: 1.5 },
{ kind: "Cointreau", qty: 1 },
{ kind: "Cranberry Juice", qty: 2 },
{ kind: "Lime Juice", qty: 1 },
],
garnish: "Lime Wheel",
served: "Straight Up",
},
}
}
-
Tutorial code: bar_menu.7.jsonnet (with inlined import)
// bar_menu.7.jsonnet
local utils = {
equal_parts(size, ingredients)::
if std.length(ingredients) == 0 then
error "No ingredients specified."
else [
{ kind: i, qty: size/std.length(ingredients) }
for i in ingredients
],
id:: function(x) x,
};
{
local my_gin = "Farmers Gin",
cocktails: {
"Bee's Knees": {
// Divide 4oz among the 3 ingredients.
ingredients: utils.equal_parts(4, [
"Honey Syrup", "Lemon Juice", my_gin]),
garnish: "Lemon Twist",
served: "Straight Up",
},
Negroni: {
// Divide 3oz among the 3 ingredients.
ingredients: utils.equal_parts(3, [
my_gin, "Sweet Red Vermouth",
"Campari"]),
garnish: "Orange Peel",
served: "On The Rocks",
},
}
}
-
Tutorial code: bar_menu.8.jsonnet
{% include examples/bar_menu.8.jsonnet %}
-
Tutorial code: bar_menu.9.jsonnet
{% include examples/bar_menu.9.jsonnet %}
-
Tutorial code: bar_menu.10.jsonnet (with inlined import)
// bar_menu.10.jsonnet
local Imported = {
cocktails: {
"Whiskey Sour": {
ingredients: [
{ kind: "Bourbon", qty: 1.5 },
{ kind: "Lemon Juice", qty: 1 },
{ kind: "Gomme Syrup", qty: 0.5 },
],
garnish: "Lemon Peel",
served: "Straight Up",
},
"Whiskey Sour With Egg": self["Whiskey Sour"] + {
ingredients: super.ingredients
+ [ { kind: "Egg White", qty: 0.5 } ],
},
}
};
Imported {
cocktails: super.cocktails {
"Whiskey Sour": {
ingredients: [
{ kind: "Scotch", qty: 1.5 },
{ kind: "Lemon Juice", qty: 0.75 },
],
garnish: "Lemon Peel",
served: "On The Rocks",
}
}
}
-
Silly example: Fibonacci via recursive function
{% include benchmarks/bench.03.jsonnet %}
-
Silly example: Fibonacci via recursive object (CAUTION: can be slow)
{% include benchmarks/bench.02.jsonnet %}