jsonnet条件生成一个字段

jsonnet conditional generation of a field

我怎样才能在 jsonnet 中使用这样的东西?

{
    if 1 == 1 then
      store: true
}

当我使用 jsonnet 运行 时出现以下错误:

STATIC ERROR: a.jsonnet:2:9-11: unexpected: if while parsing field definition

我想像这样生成一个 json,仅作为示例,但在评估某些条件时:

{
  "store": true
}

下面的代码片段实现了条件 store_Astore_B 字段,对应于 val_Aval_B 值,ab-using jsonnet [null] 评估 fieldname 将其从显示中删除

local exp_val = 1;
local val_A = 1;
local val_B = 0;

{
  [if val_A == exp_val then 'store_A' else null]: true,
  [if val_B == exp_val then 'store_B' else null]: true,
}