Pages

Friday, 20 December 2024

CSV to JSON Converter Tool



CSV to JSON Converter

CSV to JSON Converter

Upload your CSV file and convert it to JSON

Converted JSON Output

* { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Arial', sans-serif; background-color: #f4f4f9; display: flex; justify-content: center; align-items: center; min-height: 100vh; } .container { background-color: #fff; border-radius: 8px; box-shadow: 0 0 15px rgba(0, 0, 0, 0.1); width: 90%; max-width: 800px; padding: 20px; } h1 { text-align: center; color: #4caf50; font-size: 2rem; margin-bottom: 10px; } p { text-align: center; color: #555; margin-bottom: 20px; } .file-upload { text-align: center; margin-bottom: 20px; } input[type="file"] { padding: 10px; font-size: 1rem; background-color: #f1f1f1; border: 1px solid #ddd; border-radius: 5px; } button { background-color: #4caf50; color: white; border: none; padding: 10px 20px; font-size: 1rem; border-radius: 5px; cursor: pointer; margin-top: 10px; } button:hover { background-color: #45a049; } .output { margin-top: 30px; } #json-output { width: 100%; padding: 10px; font-family: monospace; background-color: #f8f8f8; border: 1px solid #ddd; border-radius: 5px; resize: none; } .download { text-align: center; margin-top: 20px; } #download-btn:disabled { background-color: #aaa; cursor: not-allowed; } @media (max-width: 600px) { .container { padding: 15px; } h1 { font-size: 1.5rem; } } document.getElementById('convert-btn').addEventListener('click', function() { const fileInput = document.getElementById('csv-file'); const file = fileInput.files[0]; if (!file) { alert('Please select a CSV file'); return; } Papa.parse(file, { complete: function(results) { const json = JSON.stringify(results.data, null, 2); document.getElementById('json-output').value = json; // Enable the download button document.getElementById('download-btn').disabled = false; // Set up download functionality document.getElementById('download-btn').addEventListener('click', function() { const blob = new Blob([json], { type: 'application/json' }); const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = 'output.json'; link.click(); }); }, header: true, // treat the first row as headers skipEmptyLines: true, // skip empty lines in CSV }); });