Created
August 9, 2019 14:22
-
-
Save nitishgupta/fbac342e372dfad47613047a4e016b88 to your computer and use it in GitHub Desktop.
Parse boolean and numbers in jsonnet from environment variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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