Search code examples
erlang

How to convert erlang variable in json format


To send an erlang data in json can be done by the following:

ReqBody = << "{\"snippet\":\"Body\" }" >>

But if I have an variable like

Temp = "data from erlang" 

how can I add Temp in this format??


Solution

  • For producing JSON you definitely should use one of JSON libraries which are better tested than your own code. I can recommend pure Erlang jsone or NIF jiffy. Do not forget that each of them needs to convert your term to proper structure.