Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Open-source data conversion utils for devs who don't like ads. Simple, lightweig
Here is the list of all utilities:

- [CSV to JSON](https://jam.dev/utilities/csv-to-json)
- [TSV to JSON](https://jam.dev/utilities/tsv-to-json)
- [Base64 Encode/Decode](https://jam.dev/utilities/base-64-encoder)
- [JSON Formatter](https://jam.dev/utilities/json-formatter)
- [YAML to JSON](https://jam.dev/utilities/yaml-to-json)
Expand All @@ -36,6 +37,7 @@ Here is the list of all utilities:
- [Image to Base64 Converter](https://jam.dev/utilities/image-to-base64)
- [Base64 to Image Converter](https://jam.dev/utilities/base64-to-image)
- [JSON to CSV](https://jam.dev/utilities/json-to-csv)
- [JSON to TSV](https://jam.dev/utilities/json-to-tsv)
- [HAR file viewer](https://jam.dev/utilities/har-file-viewer)
- [JSON to YAML](https://jam.dev/utilities/json-to-yaml)
- [Number Base Changer](https://jam.dev/utilities/number-base-changer)
Expand Down
116 changes: 116 additions & 0 deletions components/seo/JsonToTsvSEO.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import Link from "next/link";

export default function JsonToTsvSEO() {
return (
<div className="content-wrapper">
<section>
<p>
This free tool offers a quick and easy way to convert JSON files into
TSV format. If you work with data analysis, spreadsheets, or need to
import data into various applications, you can use Jam's JSON to TSV
converter to transform structured JSON data into tab-separated format.
</p>
</section>

<section>
<p>
Simply paste your JSON data and get the TSV result. Built with 💜 by
the developers at Jam, using the open-source{" "}
<a
href="https://github.com/mholt/PapaParse"
target="_blank"
rel="noopener noreferrer"
>
PapaParse
</a>{" "}
package.
</p>
</section>

<section>
<h2>How to Use Jam's JSON to TSV Converter Tool</h2>
<p>
Whether you're working on data analysis, creating reports, or
importing data into spreadsheet applications, our converter makes it
easy to convert your JSON files to TSV online.
</p>
<ul>
<li>
<b>Import JSON data:</b> <br /> Paste the JSON data you want to
convert.
</li>
<li>
<b>Get the TSV result:</b> <br /> Obtain the TSV output and copy to
clipboard.
</li>
<li>
<b>Simple and fast conversion:</b> <br /> Our tool quickly converts
JSON data into a flat TSV format, ready for use in spreadsheet
applications.
</li>
</ul>
<p>
Need to convert the other way? You can use the TSV to JSON converter{" "}
<Link href="/utilities/tsv-to-json">here</Link>.
</p>
</section>

<section>
<h2>Benefits of Converting JSON to TSV format</h2>
<p>
JSON is a flexible, easy-to-read data format used for storing
structured data. TSV (Tab-Separated Values) is a simple tabular format
widely supported by spreadsheet applications and data analysis tools.
</p>
<ul>
<li>
<b>Data Analysis:</b> <br /> TSV format is ideal for importing data
into spreadsheet applications for further analysis and
visualization.
</li>
<li>
<b>No Delimiter Conflicts:</b> <br /> Unlike CSV, TSV uses tabs as
delimiters, avoiding issues when data fields contain commas.
</li>
<li>
<b>Data Compatibility:</b> <br /> TSV is widely supported by
databases, spreadsheet tools, and data processing pipelines, making
it easier to import data into various systems.
</li>
</ul>
</section>

<section>
<h2>FAQs</h2>
<ul>
<li>
<b>Can you convert JSON to TSV?</b> <br /> Yes, our tool easily
converts JSON files to TSV format, making it perfect for data
analysis and reporting.
</li>
<li>
<b>What is the difference between TSV and CSV?</b> <br /> TSV uses
tabs to separate values while CSV uses commas. TSV is often preferred
when data fields contain commas, as it avoids quoting complexities.
</li>
<li>
<b>How accurate is the converter?</b> <br /> Our tool handles both
JSON and TSV data formats, ensuring data integrity when converting
between these formats.
</li>
<li>
<b>How easy is it to use the JSON to TSV converter?</b> <br /> Jam's
converter is user-friendly and intuitive, allowing anyone to use it
without technical knowledge. Simply paste your JSON data, and the
tool will do the rest.
</li>
<li>
<b>What types of JSON can be converted to TSV?</b> <br /> Our tool
is designed to handle simple, flat JSON structures and convert them
to TSV format effectively.
</li>
</ul>
</section>
</div>
);
}
138 changes: 138 additions & 0 deletions components/seo/TsvToJsonSEO.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import Link from "next/link";

export default function TsvToJsonSEO() {
return (
<div className="content-wrapper">
<section>
<p>
You can convert TSV files into JSON online with this free tool. If you
work with APIs, data, or web apps, you can use Jam's TSV to JSON
converter to turn tab-separated data into JSON format.
</p>
</section>

<section>
<p>
Just paste your TSV file and get the JSON result. Built with 💜 by the
developers at Jam, using the open-source{" "}
<a
href="https://github.com/mholt/PapaParse"
target="_blank"
rel="noopener noreferrer"
>
PapaParse
</a>{" "}
package.
</p>
</section>

<section>
<h2>How to Use Jam's TSV to JSON Converter Tool</h2>
<p>
Whether you're working on web development projects, data analysis, or
integrating with APIs, this converter makes it easy to convert TSV
files into JSON data.
</p>
<ul>
<li>
<b>Import TSV file:</b> <br /> Paste the TSV file you want to
convert or drag and drop a .tsv file.
</li>
<li>
<b>Get the JSON result:</b> <br /> Get the JSON output and copy to
clipboard.
</li>
<li>
<b>Lowercase keys:</b> <br /> Optionally, choose to convert all keys
in the JSON output to lowercase for consistency.
</li>
</ul>
<p>
Need to convert the other way? You can use the JSON to TSV converter{" "}
<Link href="/utilities/json-to-tsv">here</Link>.
</p>
</section>

<section>
<h2>More JSON Utilities</h2>
<p>
Beautify JSON, convert from query parameters, CSV, or YAML with Jam's
free developer utilities. They're all available in dark mode too.
</p>
<ul>
<li>
<Link href="/utilities/json-formatter">JSON Formatter</Link>: Format
and beautify your JSON data for better readability and debugging.
</li>
<li>
<Link href="/utilities/csv-to-json">CSV to JSON</Link>: Easily
convert comma-separated CSV data to JSON format.
</li>
<li>
<Link href="/utilities/yaml-to-json">YAML to JSON</Link>: Easily
convert human-readable YAML to JSON. Useful where you're working
with configuration files and need to switch between them.
</li>
</ul>
</section>

<section>
<h2>Benefits of Converting TSV to JSON format</h2>
<p>
TSV (Tab-Separated Values) is a simple file format used to store data
in tables, similar to CSV but using tabs as delimiters. JSON
(JavaScript Object Notation) is an easy-to-read data format that both
people and computers can understand.
</p>
<ul>
<li>
<b>Data Integration:</b> <br /> JSON helps merge data from TSV files
more easily in web applications, as well as APIs.
</li>
<li>
<b>Data Processing:</b> <br /> JSON is better for converting data in
different programming languages.
</li>
<li>
<b>No Delimiter Conflicts:</b> <br /> TSV avoids issues with commas
in data fields that can occur with CSV, and converting to JSON
preserves that data integrity.
</li>
</ul>
</section>

<section>
<h2>FAQs</h2>
<ul>
<li>
<b>Can you turn TSV into JSON?</b> <br /> Yes, our tool easily
converts TSV files to JSON format, making it perfect for data
integration and processing.
</li>
<li>
<b>What is the difference between TSV and CSV?</b> <br /> TSV uses
tabs to separate values while CSV uses commas. TSV is often preferred
when data fields contain commas.
</li>
<li>
<b>How accurate is the converter?</b> <br /> Our tool can handle
both TSV data and JSON data, ensuring data integrity when switching
between data formats.
</li>
<li>
<b>Is the TSV to JSON converter suitable for all types of data?</b>{" "}
<br /> Yes. Our tool can handle various types of tab-separated data.
This is beneficial for developers, data analysts, and anyone who
works with data.
</li>
<li>
<b>How easy is it to use the TSV to JSON converter?</b> <br /> Jam's
converter is user-friendly and intuitive, allowing anyone to use it
without technical knowledge. Simply paste your TSV file, and the
tool will do the rest.
</li>
</ul>
</section>
</div>
);
}
63 changes: 63 additions & 0 deletions components/utils/json-to-tsv.utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { convertJSONtoTSV } from "./json-to-tsv.utils";

describe("json-to-tsv.utils", () => {
// Helper function to normalize line endings
const normalizeTSV = (tsv: string) => tsv.replace(/\r\n/g, "\n").trim();

it("should convert a JSON string to TSV", () => {
const jsonString = '[{"name":"John","age":30},{"name":"Jane","age":25}]';
const expectedTSV = "name\tage\nJohn\t30\nJane\t25";

expect(normalizeTSV(convertJSONtoTSV(jsonString))).toBe(
normalizeTSV(expectedTSV)
);
});

it("should convert a JSON object to TSV", () => {
const jsonObject = { name: "John", age: 30 };
const expectedTSV = "name\tage\nJohn\t30";

expect(normalizeTSV(convertJSONtoTSV(jsonObject))).toBe(
normalizeTSV(expectedTSV)
);
});

it("should convert an array of JSON objects to TSV", () => {
const jsonArray = [
{ name: "John", age: 30 },
{ name: "Jane", age: 25 },
];
const expectedTSV = "name\tage\nJohn\t30\nJane\t25";

expect(normalizeTSV(convertJSONtoTSV(jsonArray))).toBe(
normalizeTSV(expectedTSV)
);
});

it("should handle empty input", () => {
expect(normalizeTSV(convertJSONtoTSV([]))).toBe("");
expect(normalizeTSV(convertJSONtoTSV({}))).toBe("");
expect(normalizeTSV(convertJSONtoTSV("[]"))).toBe("");
expect(normalizeTSV(convertJSONtoTSV("{}"))).toBe("");
});

it("should handle arrays within objects", () => {
const jsonArray = [
{ name: "John", hobbies: ["reading", "swimming"] },
{ name: "Jane", hobbies: ["painting"] },
];
const expectedTSV =
"name\thobbies\nJohn\treading,swimming\nJane\tpainting";

expect(normalizeTSV(convertJSONtoTSV(jsonArray))).toBe(
normalizeTSV(expectedTSV)
);
});

it("should throw an error for invalid input", () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(() => convertJSONtoTSV(123 as any)).toThrow(
"Input must be a JSON string or an object."
);
});
});
35 changes: 35 additions & 0 deletions components/utils/json-to-tsv.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Papa from "papaparse";

export function convertJSONtoTSV(input: string | object): string {
try {
let data: object[] = [];

if (typeof input === "string") {
data = JSON.parse(input);
} else if (Array.isArray(input)) {
data = input;
} else if (typeof input === "object") {
data = [input];
} else {
throw new Error("Input must be a JSON string or an object.");
}

const config = {
header: true,
delimiter: "\t",
newline: "\r\n",
quoteChar: '"',
escapeChar: '"',
skipEmptyLines: true,
};

const tsv = Papa.unparse(data, config);
return tsv;
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message);
} else {
throw new Error("Failed to convert JSON to TSV: Unknown error");
}
}
}
12 changes: 12 additions & 0 deletions components/utils/tools-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export const tools = [
"Easily convert CSV data to JSON format with our free tool. Quickest way to turn tabular data into a JSON format for APIs and data processing.",
link: "/utilities/csv-to-json",
},
{
title: "TSV to JSON",
description:
"Easily convert TSV data to JSON format with our free tool. Quickest way to turn tab-separated data into a JSON format for APIs and data processing.",
link: "/utilities/tsv-to-json",
},
{
title: "Base64 Encode/Decode",
description:
Expand Down Expand Up @@ -77,6 +83,12 @@ export const tools = [
"Transform your JSON data into sleek CSV format with Jam's free online converter. Simply paste your JSON and watch the magic happen!",
link: "/utilities/json-to-csv",
},
{
title: "JSON to TSV",
description:
"Transform your JSON data into TSV format with Jam's free online converter. Simply paste your JSON and get tab-separated output instantly.",
link: "/utilities/json-to-tsv",
},
{
title: "HAR file viewer",
description:
Expand Down
Loading