Skip to content

Commit d64088f

Browse files
authored
Merge pull request #155 from siddiqus/feature/json-tsv
feat: add json to tsv and tsv to json
2 parents e163b74 + f0e2d69 commit d64088f

File tree

10 files changed

+882
-0
lines changed

10 files changed

+882
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Open-source data conversion utils for devs who don't like ads. Simple, lightweig
2525
Here is the list of all utilities:
2626

2727
- [CSV to JSON](https://jam.dev/utilities/csv-to-json)
28+
- [TSV to JSON](https://jam.dev/utilities/tsv-to-json)
2829
- [Base64 Encode/Decode](https://jam.dev/utilities/base-64-encoder)
2930
- [JSON Formatter](https://jam.dev/utilities/json-formatter)
3031
- [YAML to JSON](https://jam.dev/utilities/yaml-to-json)
@@ -36,6 +37,7 @@ Here is the list of all utilities:
3637
- [Image to Base64 Converter](https://jam.dev/utilities/image-to-base64)
3738
- [Base64 to Image Converter](https://jam.dev/utilities/base64-to-image)
3839
- [JSON to CSV](https://jam.dev/utilities/json-to-csv)
40+
- [JSON to TSV](https://jam.dev/utilities/json-to-tsv)
3941
- [HAR file viewer](https://jam.dev/utilities/har-file-viewer)
4042
- [JSON to YAML](https://jam.dev/utilities/json-to-yaml)
4143
- [Number Base Changer](https://jam.dev/utilities/number-base-changer)

components/seo/JsonToTsvSEO.tsx

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import Link from "next/link";
2+
3+
export default function JsonToTsvSEO() {
4+
return (
5+
<div className="content-wrapper">
6+
<section>
7+
<p>
8+
This free tool offers a quick and easy way to convert JSON files into
9+
TSV format. If you work with data analysis, spreadsheets, or need to
10+
import data into various applications, you can use Jam's JSON to TSV
11+
converter to transform structured JSON data into tab-separated format.
12+
</p>
13+
</section>
14+
15+
<section>
16+
<p>
17+
Simply paste your JSON data and get the TSV result. Built with 💜 by
18+
the developers at Jam, using the open-source{" "}
19+
<a
20+
href="https://github.com/mholt/PapaParse"
21+
target="_blank"
22+
rel="noopener noreferrer"
23+
>
24+
PapaParse
25+
</a>{" "}
26+
package.
27+
</p>
28+
</section>
29+
30+
<section>
31+
<h2>How to Use Jam's JSON to TSV Converter Tool</h2>
32+
<p>
33+
Whether you're working on data analysis, creating reports, or
34+
importing data into spreadsheet applications, our converter makes it
35+
easy to convert your JSON files to TSV online.
36+
</p>
37+
<ul>
38+
<li>
39+
<b>Import JSON data:</b> <br /> Paste the JSON data you want to
40+
convert.
41+
</li>
42+
<li>
43+
<b>Get the TSV result:</b> <br /> Obtain the TSV output and copy to
44+
clipboard.
45+
</li>
46+
<li>
47+
<b>Simple and fast conversion:</b> <br /> Our tool quickly converts
48+
JSON data into a flat TSV format, ready for use in spreadsheet
49+
applications.
50+
</li>
51+
</ul>
52+
<p>
53+
Need to convert the other way? You can use the TSV to JSON converter{" "}
54+
<Link href="/utilities/tsv-to-json">here</Link>.
55+
</p>
56+
</section>
57+
58+
<section>
59+
<h2>More JSON Utilities</h2>
60+
<p>
61+
Beautify JSON, convert from query parameters, CSV, or YAML with Jam's
62+
free developer utilities. They're all available in dark mode too.
63+
</p>
64+
<ul>
65+
<li>
66+
<Link href="/utilities/json-formatter">JSON Formatter</Link>: Format
67+
and beautify your JSON data for better readability and debugging.
68+
</li>
69+
<li>
70+
<Link href="/utilities/json-to-csv">JSON to CSV</Link>: Convert your
71+
JSON data into comma-separated CSV format.
72+
</li>
73+
<li>
74+
<Link href="/utilities/yaml-to-json">YAML to JSON</Link>: Easily
75+
convert human-readable YAML to JSON. Useful where you're working
76+
with configuration files and need to switch between them.
77+
</li>
78+
</ul>
79+
</section>
80+
81+
<section>
82+
<h2>Benefits of Converting JSON to TSV format</h2>
83+
<p>
84+
JSON is a flexible, easy-to-read data format used for storing
85+
structured data. TSV (Tab-Separated Values) is a simple tabular format
86+
widely supported by spreadsheet applications and data analysis tools.
87+
</p>
88+
<ul>
89+
<li>
90+
<b>Data Analysis:</b> <br /> TSV format is ideal for importing data
91+
into spreadsheet applications for further analysis and
92+
visualization.
93+
</li>
94+
<li>
95+
<b>No Delimiter Conflicts:</b> <br /> Unlike CSV, TSV uses tabs as
96+
delimiters, avoiding issues when data fields contain commas.
97+
</li>
98+
<li>
99+
<b>Data Compatibility:</b> <br /> TSV is widely supported by
100+
databases, spreadsheet tools, and data processing pipelines, making
101+
it easier to import data into various systems.
102+
</li>
103+
</ul>
104+
</section>
105+
106+
<section>
107+
<h2>FAQs</h2>
108+
<ul>
109+
<li>
110+
<b>Can you convert JSON to TSV?</b> <br /> Yes, our tool easily
111+
converts JSON files to TSV format, making it perfect for data
112+
analysis and reporting.
113+
</li>
114+
<li>
115+
<b>What is the difference between TSV and CSV?</b> <br /> TSV uses
116+
tabs to separate values while CSV uses commas. TSV is often
117+
preferred when data fields contain commas, as it avoids quoting
118+
complexities.
119+
</li>
120+
<li>
121+
<b>How accurate is the converter?</b> <br /> Our tool handles both
122+
JSON and TSV data formats, ensuring data integrity when converting
123+
between these formats.
124+
</li>
125+
<li>
126+
<b>How easy is it to use the JSON to TSV converter?</b> <br /> Jam's
127+
converter is user-friendly and intuitive, allowing anyone to use it
128+
without technical knowledge. Simply paste your JSON data, and the
129+
tool will do the rest.
130+
</li>
131+
<li>
132+
<b>What types of JSON can be converted to TSV?</b> <br /> Our tool
133+
is designed to handle simple, flat JSON structures and convert them
134+
to TSV format effectively.
135+
</li>
136+
</ul>
137+
</section>
138+
</div>
139+
);
140+
}

components/seo/TsvToJsonSEO.tsx

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import Link from "next/link";
2+
3+
export default function TsvToJsonSEO() {
4+
return (
5+
<div className="content-wrapper">
6+
<section>
7+
<p>
8+
You can convert TSV files into JSON online with this free tool. If you
9+
work with APIs, data, or web apps, you can use Jam's TSV to JSON
10+
converter to turn tab-separated data into JSON format.
11+
</p>
12+
</section>
13+
14+
<section>
15+
<p>
16+
Just paste your TSV file and get the JSON result. Built with 💜 by the
17+
developers at Jam, using the open-source{" "}
18+
<a
19+
href="https://github.com/mholt/PapaParse"
20+
target="_blank"
21+
rel="noopener noreferrer"
22+
>
23+
PapaParse
24+
</a>{" "}
25+
package.
26+
</p>
27+
</section>
28+
29+
<section>
30+
<h2>How to Use Jam's TSV to JSON Converter Tool</h2>
31+
<p>
32+
Whether you're working on web development projects, data analysis, or
33+
integrating with APIs, this converter makes it easy to convert TSV
34+
files into JSON data.
35+
</p>
36+
<ul>
37+
<li>
38+
<b>Import TSV file:</b> <br /> Paste the TSV file you want to
39+
convert or drag and drop a .tsv file.
40+
</li>
41+
<li>
42+
<b>Get the JSON result:</b> <br /> Get the JSON output and copy to
43+
clipboard.
44+
</li>
45+
<li>
46+
<b>Lowercase keys:</b> <br /> Optionally, choose to convert all keys
47+
in the JSON output to lowercase for consistency.
48+
</li>
49+
</ul>
50+
<p>
51+
Need to convert the other way? You can use the JSON to TSV converter{" "}
52+
<Link href="/utilities/json-to-tsv">here</Link>.
53+
</p>
54+
</section>
55+
56+
<section>
57+
<h2>More JSON Utilities</h2>
58+
<p>
59+
Beautify JSON, convert from query parameters, CSV, or YAML with Jam's
60+
free developer utilities. They're all available in dark mode too.
61+
</p>
62+
<ul>
63+
<li>
64+
<Link href="/utilities/json-formatter">JSON Formatter</Link>: Format
65+
and beautify your JSON data for better readability and debugging.
66+
</li>
67+
<li>
68+
<Link href="/utilities/csv-to-json">CSV to JSON</Link>: Easily
69+
convert comma-separated CSV data to JSON format.
70+
</li>
71+
<li>
72+
<Link href="/utilities/yaml-to-json">YAML to JSON</Link>: Easily
73+
convert human-readable YAML to JSON. Useful where you're working
74+
with configuration files and need to switch between them.
75+
</li>
76+
</ul>
77+
</section>
78+
79+
<section>
80+
<h2>Benefits of Converting TSV to JSON format</h2>
81+
<p>
82+
TSV (Tab-Separated Values) is a simple file format used to store data
83+
in tables, similar to CSV but using tabs as delimiters. JSON
84+
(JavaScript Object Notation) is an easy-to-read data format that both
85+
people and computers can understand.
86+
</p>
87+
<ul>
88+
<li>
89+
<b>Data Integration:</b> <br /> JSON helps merge data from TSV files
90+
more easily in web applications, as well as APIs.
91+
</li>
92+
<li>
93+
<b>Data Processing:</b> <br /> JSON is better for converting data in
94+
different programming languages.
95+
</li>
96+
<li>
97+
<b>No Delimiter Conflicts:</b> <br /> TSV avoids issues with commas
98+
in data fields that can occur with CSV, and converting to JSON
99+
preserves that data integrity.
100+
</li>
101+
</ul>
102+
</section>
103+
104+
<section>
105+
<h2>FAQs</h2>
106+
<ul>
107+
<li>
108+
<b>Can you turn TSV into JSON?</b> <br /> Yes, our tool easily
109+
converts TSV files to JSON format, making it perfect for data
110+
integration and processing.
111+
</li>
112+
<li>
113+
<b>What is the difference between TSV and CSV?</b> <br /> TSV uses
114+
tabs to separate values while CSV uses commas. TSV is often
115+
preferred when data fields contain commas.
116+
</li>
117+
<li>
118+
<b>How accurate is the converter?</b> <br /> Our tool can handle
119+
both TSV data and JSON data, ensuring data integrity when switching
120+
between data formats.
121+
</li>
122+
<li>
123+
<b>Is the TSV to JSON converter suitable for all types of data?</b>{" "}
124+
<br /> Yes. Our tool can handle various types of tab-separated data.
125+
This is beneficial for developers, data analysts, and anyone who
126+
works with data.
127+
</li>
128+
<li>
129+
<b>How easy is it to use the TSV to JSON converter?</b> <br /> Jam's
130+
converter is user-friendly and intuitive, allowing anyone to use it
131+
without technical knowledge. Simply paste your TSV file, and the
132+
tool will do the rest.
133+
</li>
134+
</ul>
135+
</section>
136+
</div>
137+
);
138+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { convertJSONtoTSV } from "./json-to-tsv.utils";
2+
3+
describe("json-to-tsv.utils", () => {
4+
// Helper function to normalize line endings
5+
const normalizeTSV = (tsv: string) => tsv.replace(/\r\n/g, "\n").trim();
6+
7+
it("should convert a JSON string to TSV", () => {
8+
const jsonString = '[{"name":"John","age":30},{"name":"Jane","age":25}]';
9+
const expectedTSV = "name\tage\nJohn\t30\nJane\t25";
10+
11+
expect(normalizeTSV(convertJSONtoTSV(jsonString))).toBe(
12+
normalizeTSV(expectedTSV)
13+
);
14+
});
15+
16+
it("should convert a JSON object to TSV", () => {
17+
const jsonObject = { name: "John", age: 30 };
18+
const expectedTSV = "name\tage\nJohn\t30";
19+
20+
expect(normalizeTSV(convertJSONtoTSV(jsonObject))).toBe(
21+
normalizeTSV(expectedTSV)
22+
);
23+
});
24+
25+
it("should convert an array of JSON objects to TSV", () => {
26+
const jsonArray = [
27+
{ name: "John", age: 30 },
28+
{ name: "Jane", age: 25 },
29+
];
30+
const expectedTSV = "name\tage\nJohn\t30\nJane\t25";
31+
32+
expect(normalizeTSV(convertJSONtoTSV(jsonArray))).toBe(
33+
normalizeTSV(expectedTSV)
34+
);
35+
});
36+
37+
it("should convert a single JSON object string to TSV", () => {
38+
const jsonString = '{"name":"John","age":30}';
39+
const expectedTSV = "name\tage\nJohn\t30";
40+
41+
expect(normalizeTSV(convertJSONtoTSV(jsonString))).toBe(
42+
normalizeTSV(expectedTSV)
43+
);
44+
});
45+
46+
it("should handle empty input", () => {
47+
expect(normalizeTSV(convertJSONtoTSV([]))).toBe("");
48+
expect(normalizeTSV(convertJSONtoTSV({}))).toBe("");
49+
expect(normalizeTSV(convertJSONtoTSV("[]"))).toBe("");
50+
expect(normalizeTSV(convertJSONtoTSV("{}"))).toBe("");
51+
});
52+
53+
it("should handle arrays within objects", () => {
54+
const jsonArray = [
55+
{ name: "John", hobbies: ["reading", "swimming"] },
56+
{ name: "Jane", hobbies: ["painting"] },
57+
];
58+
const expectedTSV = "name\thobbies\nJohn\treading,swimming\nJane\tpainting";
59+
60+
expect(normalizeTSV(convertJSONtoTSV(jsonArray))).toBe(
61+
normalizeTSV(expectedTSV)
62+
);
63+
});
64+
65+
it("should throw an error for invalid input", () => {
66+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
67+
expect(() => convertJSONtoTSV(123 as any)).toThrow(
68+
"Input must be a JSON string or an object."
69+
);
70+
});
71+
});

0 commit comments

Comments
 (0)