Xbasic
json_to_csv Function
Syntax
C result = json_to_csv(txt as C)
Arguments
- txtCharacter
Result is a CSV string of CR-LF delimited rows. The first row is assumed to be the field names. Each field in the row will be separated by a comma.
Returns
- resultCharacter
A JSON string.
Description
Convert JSON to comma-delimited CSV
Discussion
Convert JSON to a CSV. Fields will be comma delimited. First row will be fields names. If a field contains a comma, enclose field in quotes. If a field contains quotes, escape quotes using two consecutive quotes.
Example
dim json as c json = <<%json% [ { "ticker" : "AAPL" , "name" : "Apple Inc." , "price:N" : "402.215" , "change:N" : "-24.025" , "mktcap" : "377.7B" , "chgPct" : "-24.025 - -5.64%"} , { "ticker" : "GOOG" , "name" : "Google Inc." , "price:N" : "780.37" , "change:N" : "-13.00" , "mktcap" : "257.3B" , "chgPct" : "-13.00 - -1.64%"} ] %json% ? json_to_csv(json) = ticker,name,price:N,change:N,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%"
See Also