how to use erlang function term_to_json?

605 Views Asked by At

I don't know how to use erlang function term_to_json and json_to_term, do I need to install some plugins or the moudule of those functions are not "erlang"?

2

There are 2 best solutions below

0
On BEST ANSWER

There is currently no such function in Erlang. There is Erlang Enhancement Proposal, which describes this:

http://www.erlang.org/eeps/eep-0018.html

but it is not yet part of the language. Fortunately, there is quite a few libraries, that solve the problem. I can recommend:

https://github.com/talentdeficit/jsx

It is actively maintained, battle tested and used internally in bigger projects like Chicago Boss.

0
On

As @tkowal has said, term_to_json and json_to_term do not exist in the erlang module.

If you are looking for a simple way to encode and decode erlang terms to and from binaries or strings you can use term_to_binary/1 or term_to_binary/2. These two functions will encode erlang terms to binaries, which can be stored or sent over the network, to be later decoded again by erlang.