[erlang-questions] Store / use JSON structure in an nice way ?

Hynek Vychodil vychodil.hynek@REDACTED
Tue Jun 16 11:40:34 CEST 2015


I think you are looking for this nice parse transform:

https://github.com/bossek/embjson

On Mon, Jun 15, 2015 at 7:07 PM, Thomas Elsgaard <thomas.elsgaard@REDACTED>
wrote:

> Hi list
>
> I am using hackney as http client (due to PATCH support), and i have an
> JSON structure in the Payload, this works very well, but it is not feeling
> really "good" to have the JSON structure in the code, and i will also need
> to have some variables in the JSON structure instead of only hardcoded
> values. What is the correct erlangish way to handle the JSON payload, is it
> really to have in the code as i have it now, or can it be placed in an
> record ?
>
> Here is the code:
>
> Method = patch,
> URL = <<"http://2.2.2.2:8081/servers/localhost/zones/xxx.gl">>,
> Headers = [{<<"X-API-Key">>, <<"xxxxxxxx">>}],
> Payload = <<"{\"rrsets\":[{\"name\": \"xxx.gl\",\"type\":
> \"A\",\"changetype\": \"REPLACE\",\"records\": [{\"content\":
> \"1.1.1.1\",\"disabled\":false,\"name\": \"xxx.gl\",\"ttl\":
> \"3600\",\"type\": \"A\",\"priority\": \"0\"}]}]}">>,
> Options = [],
> {ok, StatusCode, RespHeaders, ClientRef} = hackney:request(Method, URL,
> Headers, Payload, Options).
>
> Any hints so that it looks nice ;-)
>
> Thomas
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150616/b2ee3cf9/attachment.htm>


More information about the erlang-questions mailing list