Questions tagged [jsonnet]
Jsonnet is a data templating language which compiles to JSON.
87
questions
0
votes
1
answer
35
views
How to Install JSONNET tools on Windows-10?
I need to use this library since its a project requirements.
I am referring to official release website : https://jsonnet.org/learning/tools.html
But sadly no way find out for installation on Windows.
...
0
votes
1
answer
31
views
How to get all subdirectories in jsonnet?
I'm creating a gitlab-ci.yml file dynamically with jsonnet.
Now I want to create a job for each directory in my customers-directory.
For that I want to read all directory names into an array.
How do I ...
0
votes
1
answer
36
views
jsonnet expression to string before evaluation
Given the following jsonnetfile:
{
expression: self.result,
result: 3 > 1,
}
That evaluates to this:
{
"expression": true,
"result": true
}
Is there a way to convert ...
0
votes
1
answer
46
views
How to access a variable in Jsonnet if it's in a nested dictionary?
My goal is to make values of inner fields accessible to outer fields in a nested dictionary.
Let's say I have the following code
diction: {
"outer": "part1",
{
"...
0
votes
1
answer
33
views
Replace value in nested YAML with Jsonnet
Let's say I have the following YAML and I'd like to replace 'samsung' with 'apple' how do I do this in jsonnet? I could not find any way doing this and I'm searching for the solution since hours.
...
0
votes
1
answer
60
views
jsonnet std.map - "attempted to index array with string name" error
i am new to jsonnet
I am trying to call the name and nb seperately for different operations. But i am getting error "attempted to index array with string name" when i use "...
0
votes
2
answers
42
views
How to join two list into one on some common fields?
I want to join two list into one using deep copy.
E.g.
list1:
[
{"key1":["val1"]},
{"key2":["val2", "val3"]}
]
list2:
[
{"key2":[&...
0
votes
0
answers
30
views
jsonnet - how to create dynamic links?
I am experimenting with jsonnet to create my Grafana dashboards. One thing I want to do is add links in panels to other dynamically created dashboards. Is there a way to get what the relative link ...
1
vote
0
answers
136
views
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 ...
0
votes
1
answer
48
views
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'...
1
vote
1
answer
64
views
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, '.', '_'), '-', '_'),
}...
0
votes
1
answer
233
views
Jsonnet object comprehension in array
I know how to do Array comprehension in Jsonnet like this, with the for loop the one object in the array gets looped with all my defined values:
local values = [
'foo',
'bar',
'foobar',
];
{
...
0
votes
0
answers
22
views
EnvCommandError when poetry installing wrapt(1.13.3)
In my local, poetry install works fine and it created poetry.lock file. But when i push my changes and run the jenkins pipeline, it got stuck with Installing wrapt(1.13.3) and throws EnvCommandError..
...
0
votes
2
answers
169
views
How to replace part of string BEHIND search criteria in Jsonnet string?
I'm looking for an equivalent to std.strReplace(str, from, to) to replace parts of a string in Jsonnet. I would need from to be more like a "pattern", something like s/key="[^"]*&...
1
vote
3
answers
1k
views
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]: ...
0
votes
1
answer
118
views
Find and return element in (deep) object
I'll write "pseudo-python-jsonnet" code to show what I want to achieve.
I really have no clue how to do something like that in jsonnet.
local createCopy(gname, rname, kp) = ...
0
votes
1
answer
498
views
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 ...
2
votes
1
answer
210
views
Big cluster config managment: Kustomize or Jsonnet?
Currently I'm working with Kubeflow. It is a quite large set up with about 30 different deployments. The default manifests of the Kubeflow team is using the standard Kustomize tool to provide patches ...
0
votes
1
answer
79
views
Would like to assign multiple variables from split() on one line of code
Given the following array:
// use strings only in the form <protocol>-<port>
ports: [
'tcp-1514',
'tcp-8080',
'tcp-8443',
],
I'm trying to write jsonnet to split each element of the ...
0
votes
0
answers
133
views
how can i create a parametrized template in jsonnet that inherits the fields of a (also parametrized) 'base object' via an import?
I'm trying to use the 'OO' features of jsonnet in combination with the parametrization capabilities available via the tla arguments mechanism
I want to create templates of different kinds of events. ...
0
votes
1
answer
260
views
How do I correctly format this jsonnet array output?
I have the following JSON and am using the -y option to produce a yaml output.
{
array: [
{item1: 1},
{item2: 2},
]
}
I would like to produce (desired)
{
"array":
...
0
votes
0
answers
132
views
Overriding functions in jsonnet
I have a .libsonnet file with a JSON predefined template, it does quite a lot and it has one function i would like to override from within a .jsonnet.
The reason is that the libsonnet file is of ...
0
votes
1
answer
173
views
To use Gitlab Dashboards - How to use grafonnet with jsonnet to produce a json file that I can use with Grafana
Can someone please show me how to use the jsonnet files with grafonnet? Like a step by step for newbies?
I want to use the GitLab dashboards here in my local Grafana environment - https://gitlab.com/...
0
votes
1
answer
106
views
Object comprehension with iterator
I have a given object renameByName like that:
{
fieldA: 'foo',
fieldB: 'bar'
}
and I want to convert that into an object that is supposed to order the fields by an index:
{
fieldA: 0,
fieldB: ...
0
votes
1
answer
173
views
Increment variable from methods
I would like to increment a counter in a method, like this:
row(title, height):: {
_panels:: [],
_panelSlot:: 0,
addPanel(panel):: self {
self._panelSlot = self._panelSlot + 1,
...
0
votes
1
answer
205
views
Can a .jsonnet file be constructed in pure python
I use .jsonnet file as a template for AllenNLP model config
I search through hyperparameter space with Optuna package and evaluate that template on each step with suggested hyperparameters as extVars. ...
0
votes
1
answer
327
views
Passing TLAs from argocd to jsonnet
Trying to understand passing TLAs to my jsonnet file with argocd. This is part of my argocd application.yaml which compiles the kube-prometheus manifests straight from my main.jsonnet file. I want to ...
0
votes
1
answer
489
views
How to Populate Variables for Grafana Dashboard Template in Jsonnet
I'd like to deploy and manage many similar Grafana dashboards with jsonnet/grafonnet using a single template where variables are substituted in each dashboard instance.
A simplified example of my (not ...
1
vote
1
answer
319
views
Can I use current date as a Jsonnet variable?
I want to use current date of system (like 2021-03-01) as a variable in jsonnet.
0
votes
1
answer
106
views
Concat array elements into new array
I have a string which is separated by "/", which I then split into an array. eg.
local string = 'Code/Github/Exercises'
local array = std.split(string, "/")
// ['Code', 'Github', '...
0
votes
1
answer
425
views
As far as I can tell, there is no way to parameterize character strings in an AllenNLP config file --- only ints or floats
So the issue is that, for using autotuning (like optuna) with AllenNLP, the suggested practice is to use, in jsonnet scripts, references to environment variables, and then to set up a study to modify ...
1
vote
1
answer
1k
views
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?
...
0
votes
1
answer
172
views
How to use std.prune() with a function?
I have a function that takes one required parameter and two optional parameters. I want the function to prune out the optional parameters from the result if they are not provided, but it evaluates to ...
0
votes
1
answer
464
views
Add elements of array in jsonnet
I am trying to add elements of an array in jsonnet. Can someone post a sample?
Sample
input: [0, 1, 2, 3]
output
6
0
votes
0
answers
283
views
Is there a way to generate json-schema from jsonnet?
Jsonnet seems like a great tool for config management, and I was wondering if there's a way to generate json-schema using jsonnet?
I'm particularly interested in this because tools like react-...
1
vote
1
answer
998
views
How to build using Bazel offline
I want to build my jsonnet with Bazel. For that I am using the jsonnet rules. Unfortunately in my build pipelines I can't pull from github. So, I have been reading into offline builds, but I can't ...
1
vote
1
answer
3k
views
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 ...
0
votes
1
answer
1k
views
Using jsonnet for grafana dashboard
I am trying jsonnet (my-custom-grafana.jsonnet) for grafana dashboard.I tried below code.
local grafana = import 'grafonnet/grafana.libsonnet';
local dashboard = grafana.dashboard;
local row = grafana....
0
votes
1
answer
888
views
Using jsonnet to update Prometheus operator default rule
I am trying to override the Default rules in Kube-Prometheus-Stack.
I have enabled default rules when Kube-Prometheus-Stack was deployed.
I tried with jsonnet as shown in this example https://github....
1
vote
2
answers
977
views
jsonnet std.mapWithKey - not generating an array?
I have a local jsonnet object defined as so:
local compactRules = {
key1: "val1",
key2: "val2",
key3: "val3"
};
And I'd like to generate this array:
[
{
rule:...
3
votes
2
answers
493
views
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 ...
0
votes
1
answer
562
views
Conditional in the top level object cannot access merged config
I'm dealing with jsonnet and I cannot access to the $._config coming from the merged object
{
if ! $._config.hello.enable then {
'hello': 'world'
} else {},
} + {
_config+:: {
hello: {
...
1
vote
1
answer
2k
views
How to set a hostname in a jsonnet file?
I am trying to get the hang of jsonnet files. So far all I have is hard-coded values but what if I wanted to get the hostname for a Java application. For example in Java I would just do:
String ...
6
votes
1
answer
2k
views
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 ...
1
vote
1
answer
526
views
Addressing parent elemens from nested (children)
I have following jsonnet.
{
local property = "global variable",
property: "global property",
bar: self.property, // global property
baz: property, // global ...
2
votes
1
answer
588
views
how to replace one element of array in jsonnet with mixin way?
we have array imported from libsonnet
{
"volumes": [
{
"emptyDir": {},
"name": "grafana-storage"
},
{
"configMap": {
"name": "grafana-dashboard-apiserver"
...
1
vote
1
answer
960
views
jsonnet: How to serialize array into string
How to convert this
["a", "b", "c", "d"]
into
"a", "b", "c", "d"
in JSONNET (https://jsonnet.org/ref/stdlib.html)
2
votes
1
answer
792
views
Complex validation in Jsonnet library
What I'm trying to do is create a libsonnet library with some complex validation on the inputs, but I'm not sure how to implement this in the libsonnet file without getting null back.
I'm trying to ...
0
votes
2
answers
389
views
How do I access all the fields of an imported object?
$ cat foo.libsonnet
{
local foo = 99,
bar: [ foo, 101 ]
}
$ cat baz.jsonnet
{
local foo = import 'foo.libsonnet',
baz: [foo.foo, foo.bar]
}
$ jsonnet baz.jsonnet
RUNTIME ERROR: field ...
1
vote
1
answer
139
views
Remove kubernetes deployment based on jsonnet file
I am using jsonnet to describe deployment configuration for Kubernetes.
{
apiVersion: 'apps/v1',
kind: 'Deployment',
metadata: {
name: 'dapi-test-pod',
},
spec: {
selector: {
...