Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined function maps:to_json/1

Tags:

erlang

This is one of the things I learned from Programming Erlang, 2nd Ed, but doesn't seem to work on shell

$ erl
Erlang/OTP 17 [erts-6.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Eshell V6.2  (abort with ^G)
1> Dic = #{b => 1, a => 2}.
#{a => 2,b => 1}
2> maps:to_json(Dic).
** exception error: undefined function maps:to_json/1
3> 

What's wrong here?

like image 264
daydreamer Avatar asked Jan 06 '15 16:01

daydreamer


1 Answers

Programming Erlang, 2nd Ed was written before maps were introduced in release 17 (as experimental feature) and it seems that author of book, Joe Armstrong was too optimistic about them. Still some of proposed functionality and syntax is not yet implemented (or never will be).

Luckily, there are JSON parsers for erlang which support maps, check:

  • jiffy
  • jsx
like image 135
Łukasz Ptaszyński Avatar answered Oct 12 '22 23:10

Łukasz Ptaszyński