views:

64

answers:

1

I need to JSON-encode a list using mochiweb.

How do I get the following:

List = ["This is message 1.", "This is message 2.", "This is the last message"]
mochijson2:encode({struct,[{messages,list_to_binary(List)}]

to produce this bit of JSON:

{"messages":"["This is message 1.","This is message 2.","This is the last message"]}
+3  A: 

Actually, here it is

mochijson2:encode({
            struct,[
                {topic, list_to_binary(Topic)},
                {messages, [list_to_binary(M) || M <- List]}
            ]
        })
MattM