Forehead Solution:
Str = "[{type,a},{to,room01023123},{body,hey what up mister},{by,someone}]".
Need = [{"type","a"},{"to","room01023123"},{"body","hey what up mister"},{"by","someone"}].
L1 = string:tokens(tl(Str),",").
R=[fun(El)->Add= case El==length(L1)-1 of true->2;false->1 end,
Temp = lists:nth(X+1,L1),
{tl(lists:nth(X,L1)),lists:sublist(Temp,1,length(Temp)-Add)} end(X)
||X<-lists:seq(1,length(L1),2)].
source
share