erlang, convert list of tuples to json

867 Views Asked by At

I have a query in mnesia that returns a list of tuples like this:

[{"str", 10}, {"str2", 20}]

I want to convert it to json using jiffy but it seems jiffy:encode/1 can't do it. Is there anyway to solve my problem?!

1

There are 1 best solutions below

3
On

I don't understand what you expect but first you should provide right data format:

1> L = [{"str", 10}, {"str2", 20}].
[{"str",10},{"str2",20}]
2> jiffy:encode({[{list_to_binary(K), V} || {K, V} <- L]}).
<<"{\"str\":10,\"str2\":20}">>