Questions tagged [jsonnet]

Jsonnet is a data templating language which compiles to JSON.

Jsonnet is a domain specific configuration language that helps you define JSON data. Jsonnet lets you compute fragments of JSON within the structure, bringing the same benefit to structured data that templating languages bring to plain text.

Project info

116 questions
10
votes
1 answer

How to call parameterized Jsonnet from bash?

I can't understand how to best to parameterize a Jsonnet file so that I may call the same file from bash and from another Jsonnet file. Assuming I have a simple template called template.jsonnet: { // Required arguments name:: error "'name' must…
DazWilkin
  • 32,823
  • 5
  • 47
  • 88
8
votes
1 answer

how to write multi-line value in ksonnet/jsonnet

I want to create a kubernetes config map with multi-lines, such as this kind of yaml: apiVersion: v1 kind: ConfigMap metadata: name: nifi-bootstrap data: run.sh: |- echo "Waiting to run nslookup..." sleep 30 How should I write it in a…
Xiang Zhang
  • 2,831
  • 20
  • 40
7
votes
3 answers

Update an existing array element with jsonnet

I am using jsonnet to read in a value which consists of an array. I want to modify the first element in that array to add a value. The data structure looks like this: { "my_value": [ { "env": "something" }, { …
jaxxstorm
  • 12,422
  • 5
  • 57
  • 67
7
votes
1 answer

Importing YAML in jsonnet

Is there a way how I can import a .yaml file in jsonnet? I have found that jsonnet supports importing .json and also has a native importstr() function but looks like no support for .yaml? I would like to do: local foo = import "foo.yaml"; local bar…
Aleš
  • 8,896
  • 8
  • 62
  • 107
7
votes
3 answers

How to printf in jsonnet?

Is there a way to print the objects in jsonnet? This is for debugging purposes mainly. I am using error to print the objects but that terminates the program execution. local obj = [ { myKey: 2, }]; error 'Printing' + std.toString(obj) Outputs:…
Hakan Baba
  • 1,897
  • 4
  • 21
  • 37
6
votes
1 answer

What is the difference between the + operator and std.mergePatch in Jsonnet?

Jsonnet's std.mergePatch implements RFC7396, but in my naive testing I didn't find a different between the way it behaved and the + operator; e.g. the + operator respects x+ syntax. std.mergePatch is implemented in Jsonnet itself, which seems to…
Keith Pinson
  • 7,835
  • 7
  • 61
  • 104
5
votes
1 answer

String Interpolation in Keys in Jsonnet

I'm wondering if it's possible to have string interpolation in keys when using jsonnet? For example, I want to do something like this: { std.format("Hello %03d", 12): "milk" } But it results in STATIC ERROR: arith.jsonnet:2:5: expected token…
cdm
  • 719
  • 2
  • 10
  • 22
5
votes
1 answer

How to append an existing object in jsonnet?

How to append to an existing list? This is not valid: local list = ['a', 'b', 'c']; local list = list + ['e'];
maikel
  • 1,135
  • 1
  • 12
  • 9
5
votes
2 answers

How to correctly call jsonnet with imports from Python

I'm using jsonnet to build json objects that will be used by Python code, calling jsonnet from Python using the bindings. I want to set up my directory structure so that the jsonnet files are in a subdirectory or subdirectories relative to where…
ceridwen
  • 550
  • 2
  • 5
  • 14
5
votes
2 answers

How do I convert a string to an integer in jsonnet?

I have a string that contains a number in a Jsonnet variable. How do I convert it to an integer?
kgraney
  • 1,975
  • 16
  • 20
4
votes
1 answer

jsonnet conditional generation of a field

How can I get something like this working in jsonnet? { if 1 == 1 then store: true } I get the below error when I run it with jsonnet: STATIC ERROR: a.jsonnet:2:9-11: unexpected: if while parsing field definition I would like to generate…
Arjun
  • 385
  • 5
  • 17
4
votes
1 answer

Grafana Panel JSON to Jsonnet?

I'm able to generate Panel JSON for provisioning a Grafana dashboard like so: jsonnet -J ~/grafana/grafonnet-lib mydash.jsonnet > mydash.json However I like to manipulate and edit the resulting dashboard in Grafana itself. What I am absolutely…
hendry
  • 9,725
  • 18
  • 81
  • 139
3
votes
0 answers

Create multiple deployment manifest using k8s-libsonnet

sample.jsonnet: local k = import "github.com/jsonnet-libs/k8s-libsonnet/1.25/main.libsonnet"; { _config:: error "Must provide deploy config", // initiate resources local deploy = k.apps.v1.deployment, local namespace = k.core.v1.namespace, …
3
votes
2 answers

Combining objects with + (plus operator) vs whitespace

Jsonnet's docs mention that the + operator can be used for inheritance, or, as it's worded in the tutorial, to combine objects: { a: 1, b: 2, } + { a: 3 } However, I've noticed that - at least in simple cases like the above - simply omitting…
Mark Amery
  • 143,130
  • 81
  • 406
  • 459
3
votes
1 answer

Example for std.lines(arr) function of Jsonnet

Can anyone help me with an example for std.lines(arr) function of Jsonnet? I am trying to create a bash script to clone multiple git repositories using values from an array. My array structure is given below. gitRepo : [ { …
Sijo M Cyril
  • 660
  • 1
  • 8
  • 14
1
2 3 4 5 6 7 8