TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Transform a CSV into a JSON and vice versa

125 pointsby okumurahataabout 4 years ago

25 comments

af3dabout 4 years ago
Looks a bit like adware IMO. The library appears to be drenched in analytics. Dependencies include:<p><a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;web-vitals&#x2F;v&#x2F;0.1.0" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;web-vitals&#x2F;v&#x2F;0.1.0</a> <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;@fingerprintjs&#x2F;fingerprintjs" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;@fingerprintjs&#x2F;fingerprintjs</a><p>Harvesting user&#x27;s data, most likely...
评论 #27378264 未加载
评论 #27377896 未加载
评论 #27377829 未加载
评论 #27377678 未加载
jarofgreenabout 4 years ago
At work we work an a Python Library to do this, and much more:<p>PyPi: <a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;flattentool&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;flattentool&#x2F;</a><p>Source: <a href="https:&#x2F;&#x2F;github.com&#x2F;OpenDataServices&#x2F;flatten-tool" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;OpenDataServices&#x2F;flatten-tool</a><p>Docs: <a href="https:&#x2F;&#x2F;flatten-tool.readthedocs.io&#x2F;en&#x2F;latest&#x2F;" rel="nofollow">https:&#x2F;&#x2F;flatten-tool.readthedocs.io&#x2F;en&#x2F;latest&#x2F;</a><p>It converts JSON to CSV and vice versa but also Spreadsheet files, XML ...<p>It has recently had some work to make it memory efficient for large files.<p>Work, BTW, is an Open Data Workers Co-op working on data and standards. We use this tool a lot directly, but also as a library in other tools. <a href="https:&#x2F;&#x2F;dataquality.threesixtygiving.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;dataquality.threesixtygiving.org&#x2F;</a> for instance - this is a website that checks data against the 360 Giving Data Standard [ <a href="https:&#x2F;&#x2F;www.threesixtygiving.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.threesixtygiving.org&#x2F;</a> ].
评论 #27379470 未加载
brundolfabout 4 years ago
Slightly OT: I&#x27;ve realized that CSVs are dramatically more information-dense than the equivalent JSON, and actually make a pretty reasonable API response format if your dataset is large and fits into the tabular shape. They can be a fraction of the size, mainly because keys aren&#x27;t duplicated for every item.
评论 #27375500 未加载
评论 #27375421 未加载
评论 #27375803 未加载
评论 #27376137 未加载
评论 #27376098 未加载
评论 #27376715 未加载
earthboundkidabout 4 years ago
I wrote my own converter a few years ago, then ended up needing it again last week. It’s one of those things you don’t always need but it’s handy to have when you do. <a href="https:&#x2F;&#x2F;github.com&#x2F;baltimore-sun-data&#x2F;csv2json" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;baltimore-sun-data&#x2F;csv2json</a>
jaboabout 4 years ago
I recently heard about a tool called Miller that helps convert between JSON and CSV among other formats: <a href="https:&#x2F;&#x2F;github.com&#x2F;johnkerl&#x2F;miller" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;johnkerl&#x2F;miller</a><p><pre><code> mlr --c2j cat documents.csv &gt; documents.jsonl </code></pre> Converts a CSV file to a JSONL file
th0ma5about 4 years ago
CSV is more of a rumor than a standard, plus JSON can have a tree structure. It is a fun idea to think about and may be useful in some narrow cases, but will fail in almost all but those most trivial of structures.
评论 #27376509 未加载
评论 #27378712 未加载
nlyabout 4 years ago
jq&#x27;s stream and fromstream functions can be used to flatten and unflatten JSON. I use it all the time at work for POs who want to see data in Excel<p><a href="https:&#x2F;&#x2F;jqplay.org&#x2F;s&#x2F;ub-WvXCcPn" rel="nofollow">https:&#x2F;&#x2F;jqplay.org&#x2F;s&#x2F;ub-WvXCcPn</a><p>... from there it&#x27;s just a row-&gt;column rotation to CSV.
sireatabout 4 years ago
CSV&lt;-&gt;JSON is fundamentally an unsolvable problem because of mismatch in data hierarchies among them.<p>Plus you have the type looseness for both and lack of standards for CSV.<p>A trivial 2-D case is handled well by Python library such as Pandas. Here OP could be an alternative.<p>When I say trivial I mean flat 2 dimensional data, such as you would get from Mockaroo or similar source.<p>However in real life - data is messy.<p>As you get into 3,4 and deeper hierarchies on JSON you can&#x27;t really translate that into nice flat 2d CSV.<p>Then you have missing keys, mixed up types and you end up rolling you own hand written converters.
code-fasterabout 4 years ago
I have a couple of open source CLI tools to do this: - <a href="https:&#x2F;&#x2F;github.com&#x2F;tyleradams&#x2F;json-toolkit&#x2F;blob&#x2F;master&#x2F;csv-to-json" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tyleradams&#x2F;json-toolkit&#x2F;blob&#x2F;master&#x2F;csv-t...</a> - <a href="https:&#x2F;&#x2F;github.com&#x2F;tyleradams&#x2F;json-toolkit&#x2F;blob&#x2F;master&#x2F;json-to-csv" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tyleradams&#x2F;json-toolkit&#x2F;blob&#x2F;master&#x2F;json-...</a>
tyingqabout 4 years ago
Wouldn&#x27;t this need to allow upload&#x2F;download of CSV to really meet the spirit of the title? Or maybe replace the references of CSV with &quot;HTML Table&quot;?
评论 #27378808 未加载
robbiejsabout 4 years ago
If anyone is looking at a free tool to quickly edit CSV data in an Excel-like editor, see <a href="https:&#x2F;&#x2F;editcsvonline.com" rel="nofollow">https:&#x2F;&#x2F;editcsvonline.com</a>
somishereabout 4 years ago
Built something similar on codepen quite a few years ago. Not sure where I came up with the format, seems a bit wild looking at the v. nice dot notation used here, but possibly more useful&#x2F;efficient for variable data models, also takes into account data types:<p><a href="https:&#x2F;&#x2F;codepen.io&#x2F;theprojectsomething&#x2F;pen&#x2F;OwppWW" rel="nofollow">https:&#x2F;&#x2F;codepen.io&#x2F;theprojectsomething&#x2F;pen&#x2F;OwppWW</a><p>Note: click the <i>Toggle Info</i> to read the &quot;spec&quot; (groan) :)
osullipabout 4 years ago
I run a software company and we have a challenge when it comes to these types of conversion tools.<p>If there is any data that is a) not publicly accessible or b) contains personal information, I cannot authorise the use of a web based third party tool. There is just too much risk that some bad actor uses this as a method to soak up data.<p>I would love to verify &#x2F;validate that all of the processing is local and have some way to certify if this hasn&#x27;t changed.
hmsimhaabout 4 years ago
It would make it much easier for users to visually parse the JSON section if you added `font-family: monospace` to the textarea element
评论 #27379294 未加载
me_bxabout 4 years ago
Nice, I like the look of the editable table.<p>Shameless plug: a similar solution, working all client side, not imposing to use a key as first column, and with options regarding CSV format.<p><a href="https:&#x2F;&#x2F;mango-is.com&#x2F;tools&#x2F;csv-to-json&#x2F;" rel="nofollow">https:&#x2F;&#x2F;mango-is.com&#x2F;tools&#x2F;csv-to-json&#x2F;</a>
867-5309about 4 years ago
this can turn an HTML table into JSON with the option to download the JSON, or it can turn JSON into an HTML table with no option to download a CSV -- where does CSV come into this?<p>also, clearly javascript is a bit too ambitious for the job when e.g. PHP could provide the intended functionality with two lines of code: foreach($arrays as $values){echo implode(&#x27;,&#x27;, $values) . &quot;\n&quot;;} echo json_encode($arrays);<p>also, CSV is more for storing rigidly-structured uniform columns and rows, whereas JSON is more for storing loosely-structured varying objects, otherwise you&#x27;re redeclaring column headings in every array, which wouldn&#x27;t make much difference for gzipped transport but still wasteful and verbose nonetheless. column headings are usually the first line of a CSV
评论 #27379422 未加载
oweilerabout 4 years ago
Why doesn&#x27;t the library transform the csv into a an array of json objects?
评论 #27380303 未加载
brianzelipabout 4 years ago
FYI, the view on small devices is pretty bad - the demo json output is almost unreadable without an awkward pinch + scroll. Compare this view to the same content on the Readme via GitHub.
评论 #27378407 未加载
ddgfloridaabout 4 years ago
Shameless plug - I wrote convertcsv.com and it supports about everything you can think of as far as format conversions. JSON, XML, YAML, JSON Lines, Fixed Width, ...
AbhyudayaSharmaabout 4 years ago
You can do this in Powershell<p><pre><code> cat file.csv | ConvertFrom-Csv | ConvertTo-Json</code></pre>
darrenfabout 4 years ago
`jq` can transform CSV to JSON and vice-versa, especially for simple&#x2F;naive data where simply splitting on `,` is good enough - and where you aren&#x27;t too bothered by types (e.g. if you don&#x27;t mind numbers ending up as strings).<p>First attempt is to simply read each line in as raw and split on `,` - sort of does the job of, but it isn&#x27;t the array of arrays that you might expect:<p><pre><code> $ echo -e &quot;foo,bar,quux\n1,2,3\n4,5,6\n7,8,9&quot; &gt; foo.csv $ jq -cR &#x27;split(&quot;,&quot;)&#x27; foo.csv [&quot;foo&quot;,&quot;bar&quot;,&quot;quux&quot;] [&quot;1&quot;,&quot;2&quot;,&quot;3&quot;] [&quot;4&quot;,&quot;5&quot;,&quot;6&quot;] [&quot;7&quot;,&quot;8&quot;,&quot;9&quot;] </code></pre> Pipe that back to `jq` in slurp mode, though:<p><pre><code> $ jq -R &#x27;split(&quot;,&quot;)&#x27; foo.csv | jq -cs [[&quot;foo&quot;,&quot;bar&quot;,&quot;quux&quot;],[&quot;1&quot;,&quot;2&quot;,&quot;3&quot;],[&quot;4&quot;,&quot;5&quot;,&quot;6&quot;],[&quot;7&quot;,&quot;8&quot;,&quot;9&quot;]] </code></pre> And if you prefer objects, this output can be combined with the csv2json recipe from the jq cookbook[0], without requiring `any-json` or any other external tool:<p><pre><code> $ jq -cR &#x27;split(&quot;,&quot;)&#x27; foo.csv | jq -csf csv2json.jq [{&quot;foo&quot;:1,&quot;bar&quot;:2,&quot;quux&quot;:3}, {&quot;foo&quot;:4,&quot;bar&quot;:5,&quot;quux&quot;:6}, {&quot;foo&quot;:7,&quot;bar&quot;:8,&quot;quux&quot;:9}] </code></pre> Note that this recipe also keeps numbers as numbers!<p>In the reverse direction there&#x27;s a builtin `@csv` format string. This can be use with the second example above to say &quot;turn each array into a CSV row&quot; like so:<p><pre><code> $ jq -R &#x27;split(&quot;,&quot;)&#x27; foo.csv | jq -sr &#x27;.[]|@csv&#x27; &quot;foo&quot;,&quot;bar&quot;,&quot;quux&quot; &quot;1&quot;,&quot;2&quot;,&quot;3&quot; &quot;4&quot;,&quot;5&quot;,&quot;6&quot; &quot;7&quot;,&quot;8&quot;,&quot;9&quot; </code></pre> And to turn the fuller structure from the third example back into CSV, you can pick out the fields, albeit this one is less friendly with quotes and doesn&#x27;t spit out a header (probably doable by calling `keys` on `.[0]` only...):<p><pre><code> $ jq -cR &#x27;split(&quot;,&quot;)&#x27; foo.csv | jq -csf csv2json.jq | \ &gt; jq -r &#x27;.[]|[.foo,.bar,.quux]|@csv&#x27; 1,2,3 4,5,6 7,8,9 </code></pre> I don&#x27;t consider myself much of a jq power user, but I am a huge admirer of its capabilities.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;stedolan&#x2F;jq&#x2F;wiki&#x2F;Cookbook#convert-a-csv-file-with-headers-to-json" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;stedolan&#x2F;jq&#x2F;wiki&#x2F;Cookbook#convert-a-csv-f...</a>
评论 #27379495 未加载
gsprabout 4 years ago
I&#x27;m sorry, but why is this a website?
评论 #27378779 未加载
评论 #27379902 未加载
stevageabout 4 years ago
How do you actually load CSVs into it?
评论 #27378793 未加载
lettergramabout 4 years ago
Can this handle uploading csvs?
评论 #27378788 未加载
lumingabout 4 years ago
You should use outline instead of border in your cell css.
评论 #27378258 未加载
评论 #27378262 未加载