Dynamic import in Jsonnet

1.3k Views Asked by At

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 cases im getting the following error:

computed imports are not allowed.

I also tried to use --ext-code like here:

jsonnet -J grafonnet-lib --ext-code input=(import "./inputfile.json") createDash.jsonnet

but then I'm getting:

zsh: unknown file attribute: i

Is there any solution for this problem?

1

There are 1 best solutions below

0
On

I'm guessing zsh is gobbling up either the parenthesis or the double quotes. Drop both between single quotes.

➜  tmp jsonnet -J grafonnet-lib --ext-code input='(import "./inputfile.json")' createDash.jsonnet

{ }