miha
(Miha)
1
Hello
i have config file (json format) and need to have some variables in it, which should be populated after read is done.
exp: {“data”:“some VARIABLE”}
How to write variable in json config file to be sintactically correct and then how to populate it when file is read and unMarshaled.
tnx
miha
NobbZ
(Norbert Melzer)
2
You need to expand the variables on your own, JSON does not have something built-in.
To actually expand the shell variables just call os.ExpandEnv
after/during unmarshalling.
NobbZ
(Norbert Melzer)
4
I think I misunderstood you a bit.
I assumed you wanted to expand environment variables, but it seems as if you want to expand arbitrary variables.
Then you need to build that completely on your own.
miha
(Miha)
5
@NobbZ you mean i have to range over json string and replace it with variable, there is no other solution?
tnx
NobbZ
(Norbert Melzer)
6
Well, a quick google gave me github.com/buildkite/interpolate.
I did not use it though. It just looks as if it were able to give you what you need based on your description.
From the example it looks as if you prepare your environment and then pass it explicitely to the replacer.
miha
(Miha)
7
Thank you. This library did the trick 
system
(system)
Closed
8
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.