JSON encoding of arrays of arrays

Alessandro Sivieri alessandro.sivieri@REDACTED
Thu Oct 21 14:09:40 CEST 2010


Hi all,

I'm struggling to find out how to properly write a structure that my
MochiWeb server has to respond to a client (in JSON). The final JSON (if I
have correctly written it) should be as follows:

[
    {
        "words":
  [
      {"word": "someword1", "frequency": 10},
       {"word": "someword2", "frequency": 8},
      {"word": "someword3", "frequency": 3}
  ]
    },
{
        "words":
          [
              {"word": "someword1", "frequency": 2},
              {"word": "someword2", "frequency": 1},
              {"word": "someword3", "frequency": 5}
          ]
    },
{
        "words":
          [
              {"word": "someword1", "frequency": 4},
              {"word": "someword2", "frequency": 9},
              {"word": "someword3", "frequency": 12}
          ]
    }
]

It comes from a word frequency analysis of some documents: each "words"
element represents the output of a single document, and for each of them
there is a list of words with their frequencies. Now, how should I write the
struct in Erlang (given the fact that I am starting from a list of tuples
for each document), so that mochijson2 produces the previous JSON?
I have searched on the Web, many resources point to a video tutorial but it
does not use a list of lists, so I have not been able to find out a way to
write it...

-- 
Sivieri Alessandro
alessandro.sivieri@REDACTED
http://www.chimera-bellerofonte.eu/
http://www.poul.org/


More information about the erlang-questions mailing list