I love Elm and I strongly believe that it's the future, but I can't solve 
this one use-case that's stopping me from using it.      

I have a list of JSON objects like this:

[{a: 1, foo: "bar", bar: "baz"},
 {a: 2, foo: "baz", bar: "foo"},
 {a: 34, foo: "big", bar: "lebowski"}]

At runtime the code has no idea the types of the fields, the names of the 
fields, the number of fields, nor the number of records.

I can decode this easily in Javascript, Coffeescript, etc. How do I decode 
it in elm?


I produce reports in Javascript by pivoting the data. I do not know at 
compile time what the field names are. In Javascript I can simply do the 
following to find the relevant field names:


var foo = JSON.parse(string);
var keys = [];
for(var k in foo[0]) keys.push(k);


then later I can iterate through the records and pull out the relevant data 
doing something like so:


for(var i=0;i<foo.length;i++){
    var rec = foo[i];
    for(var j=0;j<keys.length;j++){
        var d = rec[keys[j]];
        // Do amazingly interesting things here.
    }
}


I can then manipulate that data based on user input in many different ways. 
In Javascript I certainly do not have to know field names, number of 
fields, or number of records to do interesting things with the data. In 
fact, I do this every day to generate reports, charts, etc. I can certainly 
send data from the server that describes field names, field types, etc., 
but everything needs to be done runtime as I do it in JS or Coffeescript.



Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to