<p>If you tell Papa there is a header row, each row will be organized by field name instead of index.</p>
<pre><codeclass="language-javascript">// Key data by field name instead of index/position
var results = Papa.parse(csv, {
var results = Papa.parse(csv, {
header: true
});</code></pre>
});</code></pre>
</div>
</div>
</section>
@ -362,9 +362,9 @@
@@ -362,9 +362,9 @@
<p><i>Everything</i> is parsed as strings. If you want numbers and booleans, you can enable dynamic typing to do the conversion for you.</p>
<pre><codeclass="language-javascript">// Converts numeric/boolean data
var results = Papa.parse(csv, {
var results = Papa.parse(csv, {
dynamicTyping: true
});</code></pre>
});</code></pre>
</div>
</div>
</section>
@ -383,10 +383,10 @@
@@ -383,10 +383,10 @@
<p>Okay, first off: that's really weird. But fortunately, you can skip those lines... just specify the comment string.</p>
<pre><codeclass="language-javascript">// Mostly found in academia, some CSV files
// may have commented lines in them
var results = Papa.parse(csv, {
// may have commented lines in them
var results = Papa.parse(csv, {
comments: "#"
});</code></pre>
});</code></pre>
</div>
</div>
</section>
@ -404,12 +404,12 @@
@@ -404,12 +404,12 @@
<p>Papa handles errors pretty well. The <ahref="http://tools.ietf.org/html/rfc4180">CSV standard</a> is somewhat <strike>loose</strike> ambiguous, so Papa is designed for edge cases. For example, mismatched fields won't break parsing.</p>
<pre><codeclass="language-javascript">// Example error:
{
{
type: "FieldMismatch",
code: "TooManyFields",
message: "Expected 3 fields, but parsed 4",
row: 1
}</code></pre>
}</code></pre>
</div>
</div>
</section>
@ -434,7 +434,7 @@
@@ -434,7 +434,7 @@
complete: function() {
console.log("All files done!");
}
});</code></pre>
});</code></pre>
</div>
</div>
</section>
@ -451,8 +451,8 @@
@@ -451,8 +451,8 @@
<p>Call <code>unparse()</code> instead of <code>parse()</code>, passing in your array of arrays or array of objects. Papa will figure it out.</p>
<pre><codeclass="language-javascript">// Output is a properly-formatted CSV string.
// See <ahref="/docs#json-to-csv">the docs</a> for more configurability.
var csv = Papa.unparse(yourData);</code></pre>
// See <ahref="/docs#json-to-csv">the docs</a> for more configurability.