Reading json string from env

I am using a variable in the application which I read from the vars.yml file inside kubernetes folder.

I have my variable as

AB_JSON_NAMES: {"testing12340987":"test_integration", "test_rule":"test_experiment"}

And in my code i use it as

def get_mapping(conn, _) do
    mapping = System.get_env("AB_JSON_NAMES")

    try do
      json = mapping 
        |> Poison.decode!

      conn |> render_json_response(json)
    rescue
      e -> conn |> render_json_response(%{message: "unable to decode the experiment mapping " <> mapping})
    end
  end

And it is giving me the response from the rescue block which is

{
    "message": "unable to decode the experiment mapping {u'testing12340987': u'test_carbon_integration', u'test_rule': u'test_experiment'}"
}

A strange string is formed and I am not sure how to resolve this.
Can anyone please help me knowing what is happpening.

Thanks

Is this the literal value of the text before feeding it to Poison.decode!? If so, that’s not a valid JSON.

2 Likes

Thanks @dimitarvp

Using

 '{"testing12340987":"test_carbon_integration", "test_rule":"test_experiment"}'

worked for me.

Looks like this value is a stringified Python dictionary.

2 Likes