0

I have below string in erlang which I get from Msg#archive_message.body

{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}

I need to make it

  <<"{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}">>

and pass into a function. any help is appreciated.

2 Answers 2

1

If

{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}

is a string you just need to convert it to binary with erlang:list_to_binary/1

Sign up to request clarification or add additional context in comments.

1 Comment

P_A ... thanks it works... how to convert it to normal string when we have <<"ererereer">>
1
Eshell V6.2  (abort with ^G)
1> unicode:characters_to_binary("{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}").
<<"{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}">>

Then you can use jsx to parse it into a list

2> jsx:decode(<<"{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}">>).
[{<<"message">>,<<"tttfdfdfdfdddtt">>},
 {<<"customid">>,<<"454dddfdfdfd">>}]

Or into a map

3> jsx:decode(<<"{\"message\":\"tttfdfdfdfdddtt\",\"customid\":\"454dddfdfdfd\"}">>, [return_maps]).
#{<<"customid">> => <<"454dddfdfdfd">>,
  <<"message">> => <<"tttfdfdfdfdddtt">>}

2 Comments

NO, why should we use a additional library when its possible with core functions.
list_to_binary/1 can take only up to 0..255. For example list_to_binary([322]) would crash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.