jsonnet
See:
- tutorial,
- language reference
- repo,
- go implementation,
- python binding,
- man page,
- there is also a bundler,
Install
On MacOS this did it:
brew install jsonnet
> jsonnet --version
Jsonnet commandline interpreter v0.20.0
Example Use
> jsonnet --tla-str prefix="Happy Hour " \
--tla-code brunch=true \
top-level-tla.jsonnet
{
"Happy Hour Bloody Mary": {
"garnish": "Celery salt & pepper",
"ingredients": [
{
"kind": "Vodka",
"qty": 1.5
},
{
"kind": "Tomato Juice",
"qty": 3
},
{
"kind": "Lemon Juice",
"qty": 1.5
},
{
"kind": "Worcestershire",
"qty": 0.25
},
{
"kind": "Tobasco Sauce",
"qty": 0.14999999999999999
}
],
"served": "Tall"
},
"Happy Hour Mimosa": {
"garnish": "Orange Slice",
"ingredients": [
{
"kind": "Cheap Sparkling Wine",
"qty": 3
},
{
"kind": "Orange Juice",
"qty": 3
}
],
"served": "Champagne Flute"
},
"Happy Hour Pina Colada": {
"garnish": "Pineapple slice",
"ingredients": [
{
"kind": "Rum",
"qty": 3
},
{
"kind": "Pineapple Juice",
"qty": 6
},
{
"kind": "Coconut Cream",
"qty": 2
},
{
"kind": "Ice",
"qty": 12
}
],
"served": "Frozen"
}
}
Missing switch
switch
is missing but can be replaced with a function.
switch.libsonnet
:
function(key, map) [
map[key],
][0]
Then in your foo.jsonnet
:
local switch = import 'switch.libsonnet';
local replicas = switch(cluster.account, {
prod: 100,
stage: 10,
dev: 1,
}),
Debugging Output
This prints value of clusters
and returns it:
std.trace('clusters: %s' % std.manifestJson(clusters), clusters)
std.manifestJsonMinified
Produce a string of JSON:
std.manifestJsonMinified({
account: dev_account_id,
service: business_service,
dir: kms_module_dir,
}),