Parsing JSON in Erlang

前端 未结 5 2010
一整个雨季
一整个雨季 2021-02-05 15:44

I have a piece of JSON string, which I want to parse in Erlang. It looks like:

({ id1 : [\"str1\", \"str2\", \"str3\"], id2 : [\"str4\", \"str5\"]})
5条回答
  •  我在风中等你
    2021-02-05 15:59

    Your JSON keys are not valid according to https://www.ietf.org/rfc/rfc4627.txt. Once you correct it, there are plenty of JSON libraries for Erlang, my favorite is JSX(https://github.com/talentdeficit/jsx/):

    MyJSON = { "id1" : ["str1", "str2", "str3"], "id2" : ["str4", "str5"]},
    jsx:decode(MyJSON, [return_maps]).
    

    And it will return an Erlang map data structure that can be manipulated to your needs http://learnyousomeerlang.com/maps

提交回复
热议问题