Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Created May 22, 2013 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterdavis/5628071 to your computer and use it in GitHub Desktop.
Save walterdavis/5628071 to your computer and use it in GitHub Desktop.
Convert TSV to JSON
In TextWrangler, open the TSV file and strip off the first line (header row).
Add a final Return character at the end of the file if there isn't one already.
Open the Search and Replace dialog and make sure the "GREP" checkbox is ticked.
Enter the following in the Search field:
(.+?)\t(.+?)\t(.+)\r
Enter the following in the Replace field:
["\1", "\2", "\3"],
(note there is a trailing space after the terminal comma)
Click Replace All. You should end up with this:
["PANTONE 100 C", "1016", "13"], ["PANTONE 101 C", "1016", "4.2"],
["PANTONE 102 C", "1021", "19.3"], ["PANTONE 103 C", "1012", "13.6"],
... + lots more, all on one line (wrapped here for clarity) ...
If there is a comma after the last ] character, remove it.
Add a trailing ] at the end of the file, and scroll back to the beginning and add a [.
You should end up with an array of arrays: [[a, b, c], [d, e, f], ...etc... [x, y, z]]
Save this file as colors.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment