You are on page 1of 7

<!

DOCTYPE html>
<html>
<head>
<!-- Copyright 2013 - 2018 ConvertCsv.com -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Convert JSON to CSV/Excel"/>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />

<meta http-equiv="Pragma" content="no-cache" />


<meta http-equiv="Expires" content="0" />
<title>JSON To CSV Converter</title>
<script src="/js/underscore-min.js"></script>
<script src="/js/blob.js"></script>
<script src="/js/filesaver.js"></script>
<script src="json2.js?version=1"></script>
<script src="strsup.js?v=6"></script>
<script src="localread.js?v=5"></script>
<script src="csvparse.js?v=6"></script>
<script src="csvsup.js?v=18"></script>

<script async
src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-2674404638298268",
enable_page_level_ads: true
});
</script>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"
type="text/javascript"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<script src="/js/jQuery-csv.js"></script>
<script src="https://cdn.jsdelivr.net/alasql/0.3.8/alasql.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.11.5/xlsx.full.min.js"></script>

<link rel="stylesheet" href="/js/custom.css?v=1">

<script type="text/javascript">
function assignText(s) {
document.getElementById('txt1').value = s;
}
function runit(s) {
var delimiter = radiovalue(document.forms["frm1"].outsep);
var nobreaks = document.getElementById('chkNoBreaks').checked;
var broke = document.getElementById('chkBroke').checked;
var brokeArray= document.getElementById('txtArrayName').value;
var option2 = document.getElementById('chkOption2').checked;
var A=null;
var keys={};
if (delimiter == "o") delimiter = document.getElementById("outSepOtherVal").value;
if(s.trim()!="") {
try {
A=JSON.parse(s);
}
catch(e){
try{A=eval('('+s+')');}
catch(e){
alert('Invalid JSON entered.' + (e.Description ? e.Description : ""));
return;
}
s=JSON.stringify(A);
}
if(broke && brokeArray!="") {
try {
A=JSON.parse(s);
A=eval(brokeArray);
s=JSON.stringify(A,null,4);
}catch(e){
alert("Array name or JSON not valid");
return;
}
}
if(!option2) {
try {
s=JSON.stringify(JSON.parse(s),function(key,value)
{if(_.isArray(value))keys[key]=1;return value;});
s=JSON.stringify(JSON.parse(s),function(key,value){if(!_.isArray(value) && key in
keys)return [value];return value;});
}
catch(e){;}
var inArray = [];
inArray=arrayFrom(JSON.parse(s));
var outArray = [];
for (var row in inArray) {
outArray[outArray.length] = parse_object(inArray[row]);
}
var options = {};
options.separator = delimiter;
options.headers = (document.getElementById('chkCsvHeader')).checked;
options.noBreaks = nobreaks;
var csv = $.csv.fromObjects(outArray,options);
if(options.headers && (csv.charAt(0)==='\n'||
csv.charAt(0)==='\r'))csv="Field1"+csv;
document.getElementById('txta').value = csv;
CSV.isFirstRowHeader = (document.getElementById('chkCsvHeader')).checked;
CSV.delimiter=delimiter;
CSV.autodetect = false;
CSV.parse(document.getElementById('txta').value);
document.getElementById('diva').innerHTML = csvToTable(CSV,
(document.getElementById('chkCsvHeader')).checked, false,false);
return;
// }
// catch (e) {
// ;
// }
}
//return;
{
try {
document.getElementById('txta').value = jsonToCsv(s, delimiter,
(document.getElementById('chkCsvHeader')).checked,
(document.getElementById('chkCsvQuotes')).checked, nobreaks);
CSV.isFirstRowHeader = (document.getElementById('chkCsvHeader')).checked;
CSV.delimiter=delimiter;
CSV.parse(document.getElementById('txta').value);
document.getElementById('diva').innerHTML = csvToTable(CSV,
(document.getElementById('chkCsvHeader')).checked, false,false);
}catch (e) {
if(!broke) {
alert('Invalid JSON entered.' + (e.Description ? e.Description : ""));
} else {
alert('Invalid JSON entered or JSON expression ' + brokeArray + " not valid.");
}
}
}
}

}
function prettify(text)
{
return prettyJSON(text,3);
}
function runExample(n) {
document.getElementById('chkBroke').checked = false;
document.getElementById('txt1').value=getExampleJson(n);
document.getElementById('btnRun').click()
}
</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-110011798-
1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-110011798-1');
</script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="jumbotron pageHeader">
<h1 class="text-center">Convert JSON to CSV</h1>
</div>
</div>
<div class="row">
<div class="container-fluid pageSubheader">
<h2>Use this tool to convert JSON into CSV (Comma Separated Values) or Excel.</h2>

</div>
</div>
<div class="row">
<div class="col-md-3">
<script src="/js/csvlinks.js?v=6"></script>
<script async
src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Downsides Wide -->
<ins class="adsbygoogle"
style="display:inline-block;width:300px;height:600px"
data-ad-client="ca-pub-2674404638298268"
data-ad-slot="2020261410"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

</div>
<div class="col-md-9">

<script async
src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-2674404638298268"
data-ad-slot="9209491414"
data-ad-format="auto"></ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
<p>
You can also force double quotes around each field value or it will be determined
for you.
The output CSV header row is optional.
<br/>
Your JSON input should contain an array of objects consistings of name/value
pairs.
It can also be a single object of name/value pairs
or a single object with a single property with an array of name/value pairs.
You can also identify the array using Javascript notation.
<br/>See also <a href="csv-to-json.htm">CSV to JSON</a>
and <a href="csv-to-geojson.htm">CSV to GeoJSON</a>
<br/>Plus <img src="/images/new.gif" alt="New">
Convert <a href="http://convertjson.com/json-to-xml.htm">JSON to XML</a>,
<a href="http://convertjson.com/xml-to-json.htm">XML to JSON</a>,
<a href="http://convertjson.com/jsonlint.htm">JSON Lint</a>,
<a href="http://convertjson.com/json-formatter.htm">JSON Formatter</a> and
<a href="http://convertjson.com/json-path-list.htm">Analyze JSON Paths</a>
at <a href="http://convertjson.com">ConvertJSON.com</a>
</p>

<form id="frm1" name="frm1" class="form-inline" role="form" onsubmit="return


false">
<h3 class="headerBlue">Step 1: Select your input</h3><br/>
<div class="form-group">
<b>Option 1 - Choose JSON file here</b>
<input type="file" id="f1" class="form-control"
onchange="loadTextFile(this,assignText,event)" title="Choose a local JSON file" />

<span id="spanEncoding">Encoding</span> <input type="text" id="txtEncoding"


size="8" value="" onchange="loadTextFile(document.getElementById('f1'),assignText)"
title="Enter encoding for input file or empty for default"/>
<br/><b>Option 2 - Enter an URL</b> <input type="text" size="40" value=""
name="url" id="url" class="form-control" title="Enter the URL of a web page" />
<input type="button" id="btnUrl" class="btn btn-primary" value="Load URL"
title="Load JSON via URL"
onclick="loadURL(document.getElementById('url').value)" />
<br/><b>Option 3 - paste into Text Box below</b><br/>
<textarea class="form-control" rows="10" cols="80" id="txt1"
wrap="off"></textarea>
<br/><input type="button" class="btn btn-primary" value="Clear Input"
onclick="window.location.reload(true)">
<input type="button" class="btn btn-primary" value="Format JSON" title="JSON
Pretty"
onclick="document.getElementById('txt1').value=prettify(document.getElementById('tx
t1').value)">
&nbsp; Examples:
<input type="button" class="btn btn-primary" value="1" title="Load and run
example" onclick="runExample(1)">
<input type="button" class="btn btn-primary" value="2" title="Load and run
example" onclick="runExample(2)">
<input type="button" class="btn btn-primary" value="3" title="Load and run
example" onclick="runExample(3)">
<input type="button" class="btn btn-primary" value="4" title="Load and run
example" onclick="runExample(4)">
<input type="button" class="btn btn-primary" value="5" title="Load and run
example" onclick="runExample(5)">
<input type="button" class="btn btn-primary" value="6" title="Load JSON from web
page"
onclick="document.getElementById('chkBroke').checked=false;document.getElementById(
'url').value='http://date.jsontest.com';document.getElementById('btnUrl').click()">

<br/>
<h3 class="headerBlue">Step 2: Choose output options
<small>(optional)</small></h3><a href="#" onclick="return false" data-
toggle="collapse" data-target="#p4"> <span class="glyphicon glyphicon-chevron-
down"></span></a>
<hr class="noverticalspace"/>
<fieldset class="scheduler-border collapse" id="p4">
<legend class="scheduler-border">Output Options</legend>
Output Field Separator:
<label><input type="radio" name="outsep" id="outSepComma" value=","
checked="checked"> ,</label> &nbsp;
<label><input type="radio" name="outsep" id="outSepSemicolon" value=";" >
;</label> &nbsp;
<label><input type="radio" name="outsep" id="outSepColon" value=":" > :</label>
&nbsp;
<label><input type="radio" name="outsep" id="outSepPipe" value="|" > Bar-|</label>
&nbsp;
<label><input type="radio" name="outsep" id="outSepTab" value=" "
onclick="this.value='\t'" > Tab</label> &nbsp;
<label><input type="radio" name="outsep" id="outSepOther" value="o" > Other-
Choose</label>
<label><input type="text" size="2" id="outSepOtherVal" value="*"/></label>

<br />
<label><input id="chkCsvHeader" type="checkbox" checked="checked" /> Include
header in first row</label>
<br />
<label><input type="checkbox" id="chkNoBreaks" value="Y"> Suppress Line Breaks in
Fields</label>
<br />
<label><input type="checkbox" id="chkBroke" value="Y"> Not working?</label>
If JSON variable A, name the array to convert:
<input type="text" id="txtArrayName" size="20" value="A" title="ex. A.name"
onchange="document.getElementById('chkBroke').checked=(this.value.length>0)"/>
<br/>
<label><input id="chkOption2" type="checkbox" /> Still not happy - try an
alternative conversion</label>
<br/> <label><input id="chkCsvQuotes" type="checkbox" /> Force Wrap values in
double quotes</label>
</fieldset>

<h3 class="headerBlue">Step 3: Generate output</h3><br/>


<div>
<input type="button" id="btnRun" class="btn btn-primary" value="Convert JSON To
CSV" title="Convert JSON To CSV"
onclick="runit(document.getElementById('txt1').value);return false">
<input type="button" class="btn btn-primary"
onclick="runit(document.getElementById('txt1').value);saveExcel('txta',false);retur
n false" value="JSON To Excel" title="Convert HTML Table to Excel file"/>

</div>
<br/>
<div class="form-group">
<label for="txta" class="control-label">Result Data:</label><br/>
<textarea id="txta" rows="10" cols="80" wrap="off" placeholder="Output Results"
class="form-control"></textarea>
</div><br/>
<div class="form-group form-inline">
<label>Save your result:</label>
<input type="text" size="15" id="fn" value="convertcsv" class="form-control"
title="Enter filename without extension" />.csv
<button class="btn btn-primary"
onclick="saveFile(document.getElementById('txta').value,'csv');return false"><span
class="glyphicon glyphicon-save-file"></span> Download Result</button>
<label title="End-of-Line">EOL: <select id="eol"
title="CRLF=Windows,LF=Unix/Linux/New Apple/Android"><option
value="">CRLF</option><option value="LF">LF</option></select></label>
<br/>
</div>

</form>
<div id="diva"></div>
<br/>
<script async
src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ResponsiveAd -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-2674404638298268"
data-ad-slot="9209491414"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

<br/>

</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel-footer">
<script src="/js/footer.js"></script>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

You might also like