Skip to content

Instantly share code, notes, and snippets.

@nitishgupta
Created August 9, 2019 14:22
Show Gist options
  • Save nitishgupta/fbac342e372dfad47613047a4e016b88 to your computer and use it in GitHub Desktop.
Save nitishgupta/fbac342e372dfad47613047a4e016b88 to your computer and use it in GitHub Desktop.
Parse boolean and numbers in jsonnet from environment variables
{
boolparser(x)::
if x == "true" then true
else false
}
{
parse_number(x)::
local a = std.split(x, ".");
if std.length(a) == 1 then
std.parseInt(a[0])
else
local denominator = std.pow(10, std.length(a[1]));
local numerator = std.parseInt(a[0] + a[1]);
local parsednumber = numerator / denominator;
parsednumber
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment