A couple of quick json questions

Hi, I’m trying to run http_post/4 as

http_post(Endpoint,json([environmentName='PRODUCTION']),Resp,[]).

where a param of the data I’m trying to post starts with a capital letter.

When I try to post just as you see above I get

ERROR: Type error: `json_term' expected, found `environmentName='PRODUCTION'' (a compound)

What can I do to get around this? I also tried double quotes but I get the same error. If I leave the quotes off it becomes a variable.

Also, per the doc “Data is posted using http_post_data/3“ and per http_post_data/3 that should should be the “classical“ json(+Term). Is the new representation as Data= _{environmentName:'PRODUCTION'} supported here or if I have that would I need to convert it to a term first?

I think you need json twice. The outer is to tell http_post/4 you want to post JSON and the inner the specify the object.

Using dicts, this should become

http_post(URL, json(#{environmentName:'PRODUCTION'}), Resp, []).

I don’t get that. What is “it” and to what do you like to convert it to? Dicts are written as Tag{k1:v1, …}, where Tag is an atom or variable. I’ve become used to use # as Tag for anonymous dicts. The parser deals with that. You can create (or disassemble) them at runtime from data using dict_pairs/3

I meant if I have Data = _{environmentName:'PRODUCTION'} then would I need to do anything like

Data = _{environmentName:'PRODUCTION'},
dict_to_term(Data,Data_term),
http_post(Endpoint,data(Data_term),Resp,[]).

to make it work, but I think you answered my question. Thanks.