stanf 43 Posted December 24, 2016 Report Share Posted December 24, 2016 i have a csv file that i need to convert into a json file.can someone provide my with instructions in how to do this. Quote Link to post Share on other sites
LoWrIdErTJ - BotGuru 904 Posted December 24, 2016 Report Share Posted December 24, 2016 I do so via phpthis way I can load csv data to it and then convert to json Quote Link to post Share on other sites
stanf 43 Posted December 24, 2016 Author Report Share Posted December 24, 2016 do you want to part with it? Quote Link to post Share on other sites
LoWrIdErTJ - BotGuru 904 Posted December 24, 2016 Report Share Posted December 24, 2016 // path to file $file="1_23.csv"; // reads in the file $csv= file_get_contents($file); // creates array of data $array = array_map("str_getcsv", explode("\n", $csv)); // encodes to json $json = json_encode($array); // returns json data print_r($json); Quote Link to post Share on other sites
stanf 43 Posted December 24, 2016 Author Report Share Posted December 24, 2016 thanx tji have xamp installed on this machine, so i gonna play with Quote Link to post Share on other sites
Bot-Factory 602 Posted December 27, 2016 Report Share Posted December 27, 2016 http://www.csvjson.com/csv2json Someone might even automate that site somehow Quote Link to post Share on other sites
deliter 203 Posted December 30, 2016 Report Share Posted December 30, 2016 set table cell(&myT,0,0,"Apples") set table cell(&myT,0,1,"Oranges") set table cell(&myT,1,0,1) set table cell(&myT,1,1,3) run javascript("//var csv is the CSV file with headers function csvJSON(csv)\{ var lines=csv.split(\"\\n\"); var result = []; var headers=lines[0].split(\",\"); for(var i=1;i<lines.length;i++)\{ var obj = \{\}; var currentline=lines[i].split(\",\"); for(var j=0;j<headers.length;j++)\{ obj[headers[j]] = currentline[j]; \} result.push(obj); \} //return result; //JavaScript object return JSON.stringify(result); //JSON \}") alert($eval("csvJSON(`{&myT}`)")) Remember the little ` ` marks for the eval bit, if your csv's have that symbol the code will break but I doubt they would**Does not work with Chrome 21 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.