Skip to content
Home
Tools
Date & Time
Education & Learning
Financial & Business
Gaming & Entertainment
Health & Fitness
Image & Graphics
Math & Number
PDF & Document
Video Tools
Text & Writing
Unit & Measurement Converters
Social Media
SEO & Marketing
Random Generators & Fun Tools
Productivity
Password & Security
Other Utilities / Miscellaneous
About Us
Blog
Home
Tools
Date & Time
Education & Learning
Financial & Business
Gaming & Entertainment
Health & Fitness
Image & Graphics
Math & Number
PDF & Document
Video Tools
Text & Writing
Unit & Measurement Converters
Social Media
SEO & Marketing
Random Generators & Fun Tools
Productivity
Password & Security
Other Utilities / Miscellaneous
About Us
Blog
Search
JSON Converter
JSON Converter
Convert JSON to various formats instantly
Input JSON
0 chars
{ "store": { "name": "Book Haven", "location": "Downtown", "books": [ { "id": "B001", "title": "The Great Adventure", "author": "John Writer", "price": 24.99, "categories": ["Fiction", "Adventure"], "inStock": true, "details": { "pages": 350, "publisher": "BookHouse Inc", "year": 2023 } }, { "id": "B002", "title": "Data Science Mastery", "author": "Dr. Data", "price": 49.99, "categories": ["Education", "Technology"], "inStock": true, "details": { "pages": 450, "publisher": "TechPress", "year": 2024 } } ], "employees": [ { "id": 1, "name": "Alice Johnson", "position": "Manager", "email": "alice@bookhaven.com" }, { "id": 2, "name": "Bob Smith", "position": "Sales Associate", "email": "bob@bookhaven.com" } ] } }
Converted Output
0 chars
Copy Output
Download
Conversion Formats
JSON to JAVA
JSON to XML
JSON to YAML
JSON to CSV
JSON to TSV
JSON to Text
JSON to Excel
JSON to HTML
XSLT Transformation
Convert JSON
Copy Result
Download Result
Clear All
Validate JSON
Beautify JSON
0 B
Input Size
0 B
Output Size
0ms
Conversion Time
JAVA
Current Format
JAVA Format:
Converts JSON to Java classes with getters and setters. Perfect for Java developers who need to create POJOs from JSON data.
Converted content copied to clipboard!
`; return html; } // Beautify JSON function beautifyJson() { try { const jsonData = JSON.parse(inputJson.value); inputJson.value = JSON.stringify(jsonData, null, 2); showToast("JSON beautified successfully!"); updateCounts(); hideError(); } catch (error) { showError("Invalid JSON: " + error.message); } } // Download file function function downloadFile(content, filename, mimeType) { const blob = new Blob([content], { type: mimeType }); const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = filename; document.body.appendChild(link); link.click(); document.body.removeChild(link); setTimeout(() => { URL.revokeObjectURL(link.href); }, 100); } // Generate filename based on format and timestamp function generateFilename() { const timestamp = new Date().toISOString().replace(/[:.]/g, '-').split('T')[0]; const extension = formatExtensions[currentFormat] || '.txt'; return `json-converted-${timestamp}-${Date.now()}${extension}`; } // Download converted result function downloadConvertedResult() { const content = outputContent.value.trim(); if (!content) { showToast("No content to download"); return; } const filename = generateFilename(); const mimeType = formatMimeTypes[currentFormat] || 'text/plain'; downloadFile(content, filename, mimeType); showToast("File downloaded successfully!"); } // Main conversion function function convertJson() { const startTime = performance.now(); const jsonString = inputJson.value.trim(); if (!jsonString) { showError("Please enter JSON to convert"); return; } try { const jsonData = parseJson(jsonString); let result; switch (currentFormat) { case 'java': result = jsonToJava(jsonData); break; case 'xml': result = jsonToXml(jsonData); break; case 'yaml': result = jsonToYaml(jsonData); break; case 'csv': result = jsonToCsv(jsonData); break; case 'tsv': result = jsonToTsv(jsonData); break; case 'text': result = jsonToText(jsonData); break; case 'excel': result = jsonToExcel(jsonData); break; case 'html': result = jsonToHtml(jsonData); break; default: result = jsonToJava(jsonData); } outputContent.value = result; // Update conversion time const endTime = performance.now(); conversionTime.textContent = Math.round(endTime - startTime) + 'ms'; } catch (error) { showError(error.message); } updateCounts(); } // Show error message function showError(message) { inputError.textContent = message; inputError.style.display = 'block'; setTimeout(() => { inputError.style.display = 'none'; }, 5000); } function hideError() { inputError.style.display = 'none'; } // Show toast notification function showToast(message) { toast.innerHTML = `
${message}`; toast.style.display = 'flex'; setTimeout(() => { toast.style.display = 'none'; }, 3000); } // Copy to clipboard function copyToClipboard() { if (!outputContent.value.trim()) { showToast("No content to copy"); return; } outputContent.select(); outputContent.setSelectionRange(0, 99999); try { navigator.clipboard.writeText(outputContent.value); showToast("Converted content copied to clipboard!"); } catch (err) { // Fallback for older browsers document.execCommand('copy'); showToast("Content copied to clipboard!"); } } // Copy output to clipboard (from output button) function copyOutputToClipboard() { if (!outputContent.value.trim()) { showToast("No output to copy"); return; } outputContent.select(); outputContent.setSelectionRange(0, 99999); try { navigator.clipboard.writeText(outputContent.value); showToast("Output copied to clipboard!"); } catch (err) { document.execCommand('copy'); showToast("Output copied to clipboard!"); } } // Validate JSON function validateJson() { const jsonString = inputJson.value.trim(); if (!jsonString) { showToast("Please enter JSON to validate"); return; } try { JSON.parse(jsonString); showToast("JSON is valid!"); hideError(); } catch (error) { showError("Invalid JSON: " + error.message); } } // Clear all fields function clearAll() { inputJson.value = ''; outputContent.value = ''; xsltContent.value = ''; conversionTime.textContent = '0ms'; updateCounts(); showToast("All fields cleared"); hideError(); } // Event Listeners inputJson.addEventListener('input', updateCounts); outputContent.addEventListener('input', updateCounts); convertBtn.addEventListener('click', convertJson); copyBtn.addEventListener('click', copyToClipboard); downloadBtn.addEventListener('click', downloadConvertedResult); clearBtn.addEventListener('click', clearAll); validateBtn.addEventListener('click', validateJson); beautifyBtn.addEventListener('click', beautifyJson); // Output action buttons outputCopyBtn.addEventListener('click', copyOutputToClipboard); outputDownloadBtn.addEventListener('click', downloadConvertedResult); // Auto-convert on format change if there's content formatBtns.forEach(btn => { btn.addEventListener('click', function() { if (inputJson.value.trim()) { setTimeout(convertJson, 100); } }); }); // Initial conversion convertJson(); });