Reading json config file with variables in it

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

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.

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.

@NobbZ you mean i have to range over json string and replace it with variable, there is no other solution?

tnx

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.

Thank you. This library did the trick :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.