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, ".", "_") }
for u in users
];
{
data: {
[user.replaced_username]: {
username: user.username,
} for user in users_new
}
}
The error message is like this:
RUNTIME ERROR: Field does not exist: strReplace
templates/users.jsonnet:5:32-45 object <anonymous>
templates/users.jsonnet:11:17-38 thunk <b>
std.jsonnet:148:27 thunk <vals>
std.jsonnet:611:21-24
std.jsonnet:611:12-25 thunk <a>
std.jsonnet:611:12-36 function <anonymous>
std.jsonnet:611:12-36 function <anonymous>
std.jsonnet:148:13-28 function <anonymous>
templates/users.jsonnet:11:10-38 object <anonymous>
During manifestation
As I understand from the error message I can't use calculated values in keys or do I miss something here?
UPD: Turned out that std.strReplace
function is not present in jsonnet version 0.9.5. Problem solved by copying that function into a template.