[Proto-Scripty] Re: CSV to Json

2011-08-22 Thread Victor
You can invert your {'fields': [{'field':'fname', 'col':2}, {'field':'ssn', 'col':5}]} to something like ['field0', 'field1', 'fname', 'field3', 'field4', 'ssn'] and then zip it (Enumerable#zip) with every CSV row. -- You received this message because you are subscribed to the Google Groups

[Proto-Scripty] Re: CSV to Json

2011-08-22 Thread Eric
Jason, Why do you copy the return array into an other one before using it? (and why rewriting code already available as native PHP functions?) This should do the same than your code: $fh = fopen($filename); $fields = fgetcsv($fh); while($line = fgetcsv($fh) !== false) { print

[Proto-Scripty] Re: CSV to Json

2011-08-22 Thread Jason
Eric - that is smoother, I'll update my scripts to run it that way thanks! On Aug 22, 5:01 am, Eric lefauv...@gmail.com wrote: Jason, Why do you copy the return array into an other one before using it? (and why rewriting code already available as native PHP functions?) This should do

[Proto-Scripty] Re: CSV to Json

2011-08-21 Thread kstubs
Client side only.. I have something written but not sure I'm taking advantage of prototype added methods for arrays and enumerations. Basically, I'm constructing a csv from json object iterating over it's data array, and appending to CSV like: csv+=data csv+=',' csv+='\n' The above is

[Proto-Scripty] Re: CSV to Json

2011-08-20 Thread Jason
I would use a small PHP script (assuming the first line is the field names) $fields = array(); $data = array(); $fh = fopen($filename); $line = fgetcsv($fh); foreach($line as $n) { $fields[] = $n; } while($line = fgetcsv($fh) !== false) { foreach($line as $key = $n) { $data[$fields[$key]][] =