Extension::JsonJsonFromCSV Method

Syntax

.JsonFromCSV as c (csv as C)

Arguments

csv

Text containing comma separated values, first row must contain the field names to use.

Description

Convert CSV data to a JSON array - the first row of the CSV must be contain the field names.

Example

dim txt as c 
txt = <<%txt%
ticker,name,price,change,mktcap,chgPct
"AAPL","Apple Inc.",402.215,"-24.025",377.7B,"-24.025 - -5.64%"
"GOOG","Google Inc.",780.37,"-13.00",257.3B,"-13.00 - -1.64%"
"MSFT","Microsoft Corpora",28.8349,"-0.1351",241.5B,"-0.1351 - -0.47%"
"INTC","Intel Corporation",22.067,"+0.152",109.1B,"+0.152 - +0.69%"
"HPQ","Hewlett-Packard C",20.48,"-0.55",39.814B,"-0.55 - -2.62%"
"ORCL","Oracle Corporatio",32.528,"-0.887",153.2B,"-0.887 - -2.65%"
"CSCO","Cisco Systems, In",20.625,"-0.535",110.0B,"-0.535 - -2.53%"
"DELL","Dell Inc.",14.005,"-0.035",24.470B,"-0.035 - -0.25%"
"YHOO","Yahoo! Inc.",23.696,"-0.094",26.096B,"-0.094 - -0.40%"
"FB","Facebook, Inc.",26.5912,"-0.3288",63.344B,"-0.3288 - -1.22%"
"LNKD","LinkedIn Corporat",180.29,"-2.18",19.661B,"-2.18 - -1.19%"
"GRPN","Groupon, Inc.",6.37,"-0.01",4.194B,"-0.01 - -0.16%"
"YELP","Yelp Inc. Class A",25.545,"-0.165",1.628B,"-0.165 - -0.64%"
%txt%
? extension::json::JsonFromCSV(txt)
= [
{ "ticker" : "AAPL" , "name" : "Apple Inc." , "price" : "402.215" , "change" : "-24.025" , "mktcap" : "377.7B" , "chgPct" : "-24.025 - -5.64%"} ,
{ "ticker" : "GOOG" , "name" : "Google Inc." , "price" : "780.37" , "change" : "-13.00" , "mktcap" : "257.3B" , "chgPct" : "-13.00 - -1.64%"} ,
{ "ticker" : "MSFT" , "name" : "Microsoft Corpora" , "price" : "28.8349" , "change" : "-0.1351" , "mktcap" : "241.5B" , "chgPct" : "-0.1351 - -0.47%"} ,
{ "ticker" : "INTC" , "name" : "Intel Corporation" , "price" : "22.067" , "change" : "+0.152" , "mktcap" : "109.1B" , "chgPct" : "+0.152 - +0.69%"} ,
{ "ticker" : "HPQ" , "name" : "Hewlett-Packard C" , "price" : "20.48" , "change" : "-0.55" , "mktcap" : "39.814B" , "chgPct" : "-0.55 - -2.62%"} ,
{ "ticker" : "ORCL" , "name" : "Oracle Corporatio" , "price" : "32.528" , "change" : "-0.887" , "mktcap" : "153.2B" , "chgPct" : "-0.887 - -2.65%"} ,
{ "ticker" : "CSCO" , "name" : "Cisco Systems, In" , "price" : "20.625" , "change" : "-0.535" , "mktcap" : "110.0B" , "chgPct" : "-0.535 - -2.53%"} ,
{ "ticker" : "DELL" , "name" : "Dell Inc." , "price" : "14.005" , "change" : "-0.035" , "mktcap" : "24.470B" , "chgPct" : "-0.035 - -0.25%"} ,
{ "ticker" : "YHOO" , "name" : "Yahoo! Inc." , "price" : "23.696" , "change" : "-0.094" , "mktcap" : "26.096B" , "chgPct" : "-0.094 - -0.40%"} ,
{ "ticker" : "FB" , "name" : "Facebook, Inc." , "price" : "26.5912" , "change" : "-0.3288" , "mktcap" : "63.344B" , "chgPct" : "-0.3288 - -1.22%"} ,
{ "ticker" : "LNKD" , "name" : "LinkedIn Corporat" , "price" : "180.29" , "change" : "-2.18" , "mktcap" : "19.661B" , "chgPct" : "-2.18 - -1.19%"} ,
{ "ticker" : "GRPN" , "name" : "Groupon, Inc." , "price" : "6.37" , "change" : "-0.01" , "mktcap" : "4.194B" , "chgPct" : "-0.01 - -0.16%"} ,
{ "ticker" : "YELP" , "name" : "Yelp Inc. Class A" , "price" : "25.545" , "change" : "-0.165" , "mktcap" : "1.628B" , "chgPct" : "-0.165 - -0.64%"}
]