Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since you asked for inspiration, I can immagine two directions you can take</p> <ol> <li><p>You can write code to hand-role your own JSON which, if your need is modest enough, can be a very light-weight and appropriate solution. It would be pretty simple Erlang to take that one data-structure and convert it to the JSON.</p> <p>"[[{\"id1\":1},{\"id2\":2},{\"id3\":3},{\"id4\":4}],[{\"id1\":5},{\"id2\":6} {\"id3\":7},{\"id4\":8}]]"</p></li> <li><p>You can produce a data-structure that mochiweb's mochijson:encode/1 and decode/1 can handle. I took your list and hand coded it to JSON, getting:</p> <p>X = "[[{\"id1\":1},{\"id2\":2},{\"id3\":3},{\"id4\":4}],[{\"id1\":5},{\"id2\":6},{\"id3\":7},{\"id4\":8}]]".</p></li> </ol> <p>then I used mochison:decode(X) to see what structure mochiweb uses to represent JSON (too lazy to look at the documentation). </p> <pre><code>Y = mochijson:decode(X). {array,[{array,[{struct,[{"id1",1}]}, {struct,[{"id2",2}]}, {struct,[{"id3",3}]}, {struct,[{"id4",4}]}]}, {array,[{struct,[{"id1",5}]}, {struct,[{"id2",6}]}, {struct,[{"id3",7}]}, {struct,[{"id4",8}]}]}]} </code></pre> <p>So, if you can create this slightly more elaborate data structure then the one you are using, then you can get the JSON by using mochijson:encode/1. Here is an example imbeddied in an io:format statement so that it prints it as a string -- often you would use the io_lib:format/X depending on your application.</p> <pre><code>io:format("~s~n",[mochijson:encode(Y)]). [[{"id1":1},{"id2":2},{"id3":3},{"id4":4}],[{"id1":5},{"id2":6},{"id3":7},{"id4":8}]] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload