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
2
votes
2 answers

How to use local variables in arrays?

I want to write a function that returns an array. The array contains objects, where some of them need to reuse a certain object (metadata in this example). This object depends on a parameter of the function and repeating it would be a bit…
svenwltr
  • 17,002
  • 12
  • 56
  • 68
2
votes
1 answer

Using go-jsonnet to return pure JSON

I am using Google's go-jsonnet library to evaluate some jsonnet files. I have a function, like so, which renders a Jsonnet document: // Takes a list of jsonnet files and imports each one and mixes them with "+" func renderJsonnet(files []string,…
jaxxstorm
  • 12,422
  • 5
  • 57
  • 67
2
votes
1 answer

How to replace string for each item in a list in jsonnet?

How to replace a value in a list in jsonnet. The basic example like this does not seem to work: local users = import "../data/users.json"; // replace dots in username local users_new = [ u + { replaced_username: std.strReplace(u.username, ".",…
Anton Babenko
  • 6,586
  • 2
  • 36
  • 44
1
vote
1 answer

Partially interpolate a format string in Jsonnet

Suppose I want to do: local formatString = "Name: %(a)s Age: %(b)s"; local v = formatString % {a: "a"}; { asd: v % {b: "1"} } The above doesn't compile, is there any way to achieve this goal of doing string interpolation in two steps? one thing…
Nate W
  • 35
  • 5
1
vote
1 answer

jsonnet import local variable from another jsonnet file

I have a a.libsonnet file: local panel = { new(...)::{... }, createFromConfig(config):: this.new(), }; local config = std.extVar('config'); panel.createFromConfig(config) It seams if i only do in another file local panel = import…
Tomas Wen
  • 37
  • 8
1
vote
1 answer

Tanka/Jsonnet - Howto loop over templates/imports?

i am trying to create multiple grafana-instances with slightly different config-files with tanka. The following works, as long as the the configmap.grafana_ini is in-place. But this becomes very unreadable with a growing config. So i am looking for…
strowi
  • 27
  • 3
1
vote
1 answer

Referencing a loop object

i am currently checking out tanka + jsonnet. But evertime i think i understand it... sth. new irritates me. Can somebody help me understand how to do a loop-reference? (Or general better solution?) Trying to create multiple deployments with a…
strowi
  • 27
  • 3
1
vote
1 answer

How to use local variables in object comprehension

I'm trying to do the following: main.jsonnet local data = import 'data.libsonnet'; { ["build:"+client]: { variables: data.getVariables(client, "build") } for client in data.clients } data.libsonnet getVariables(client, stage)…
1
vote
1 answer

Jsonnet - variable turned into literal string

I'm having trouble with this snippet where I want to pass in value using a variable but it becomes a literal string. test: if variableA then { 'hello': '{"foo": bar}' }, I want to be to be variable and I expect bar to be the value I've passed in…
hitman222
  • 179
  • 4
  • 10
1
vote
1 answer

Dynamic import in Jsonnet

I want to get input file in Jsonnet so the following is working great for me: local input = import './inputfile.json'; Problem is that I want to pass the file name through the Jsonnet CLI and I tried to use --ext-str or TLA but in both…
1
vote
1 answer

Computed fields cannot access local variables?

I have the following block of code: local tst = { postgres: { test: { // params: ['blahblah'], }, }, }; { [if std.length(std.objectFields(tst)) > 0 then 'aws_db_parameter_group']: { ['pgsql_%s' % db]: { local database…
NarūnasK
  • 4,564
  • 8
  • 50
  • 76
1
vote
1 answer

function for multi char replacement in jsonnet

How can I replace multiple chars in a string? My current strategy is to nest the stdlib functions: tst.jsonnet: local tst = '0-1.2'; { tst: std.strReplace(std.strReplace(tst, '.', '_'), '-', '_'), } output: > ./jsonnet tst.jsonnet { "tst":…
NarūnasK
  • 4,564
  • 8
  • 50
  • 76
1
vote
3 answers

how to do proper for-loops in jsonnet?

Each time I think I finally understood jsonnet, it comes around to hit me in the face ... -.- I have something like the following: local applyModifications(kp) = { [topLvlKey]: { [subKey]: myfunction(kp[topLvlKey][subKey]) for subKey in…
Heiko Finzel
  • 78
  • 1
  • 8
1
vote
1 answer

Build multiple jsonnet files at once

The current jsonnet compiler only allows compile one file at a time. Is there any way to build many jsonnet files in one command, maybe with a rule like all jsonnet files matching pattern *.jsonnet in folder recursively?
Nolan Edric
  • 406
  • 4
  • 13
1
vote
1 answer

Failed to install jsonnet on google cloud run

I am trying to build a image for deploying a code on google cloud run with the jsonnet python package, it fails to install jsonnet with following error. Any ideas what can I do to resolve this? Running setup.py install for jsonnet: started Running…
Duumb Eeee
  • 56
  • 6