Hi,
"
stanislaw...@gmail.com" <
stanislaw...@gmail.com> writes:
> {
> [if false then "media-missing"]: {
> foo: "bar"
> },
> [if true then "media-true"]: {
> foo: "bar"
> },
> "media-null": if false then {
> foo: "bar"
> }
> }
Playing with this, it seems like the set of the object's keys are
constructed *before* the object's scope. In particular, inside a
conditional key definition, one may not use another key/value item from
the object, nor an object-local variable. Values defined outside the
scope of the object may be used inside conditional key definitions.
Is this a Jsonnet language feature or is it dependent on the particular
Jsonnet interpreter?
Some examples:
```
$ jsonnet --version
Jsonnet commandline interpreter v0.13.0
$ cat junk.jsonnet
{
as: {deps:[1,2]},
[if std.objectHas($.as, "deps") then "deps"]: $.as.deps,
}
$ jsonnet junk.jsonnet
STATIC ERROR: junk.jsonnet:3:23: No top-level object found.
$ cat junk.jsonnet
{
local as = {deps:[1,2]},
[if std.objectHas(as, "deps") then "deps"]: as.deps,
}
$ jsonnet junk.jsonnet
STATIC ERROR: junk.jsonnet:3:23-25: Unknown variable: as
```
A "global local" is usable:
```
$ cat junk.jsonnet
local as = {deps:[1,2]};
{
[if std.objectHas(as, "deps") then "deps"]: as.deps,
}
$ jsonnet junk.jsonnet
{
"deps": [
1,
2
]
}
```
Cheers,
-Brett.