JSON to Text Tool code

 JSON to Text Tool code is written in css, Javascript and html.

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>JSON to Text Tool</title>

    <style>

        body {

            font-family: Arial, sans-serif;

            margin: 0;

            padding: 0;

            display: flex;

            flex-direction: column;

            align-items: center;

            background: #f3f4f6;

            color: #333;

        }


        header {

            width: 100%;

            background: linear-gradient(90deg, #4caf50, #2196f3);

            color: #fff;

            padding: 20px 0;

            text-align: center;

            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);

        }


        header h1 {

            margin: 0;

            font-size: 2em;

        }


        main {

            width: 90%;

            max-width: 800px;

            margin: 20px auto;

            padding: 20px;

            background: #fff;

            border-radius: 8px;

            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);

        }


        .input-section, .output-section {

            margin-bottom: 20px;

        }


        label {

            display: block;

            font-weight: bold;

            margin-bottom: 8px;

        }


        textarea {

            width: 100%;

            height: 150px;

            padding: 10px;

            font-size: 1em;

            border: 1px solid #ddd;

            border-radius: 4px;

            resize: none;

        }


        textarea:focus {

            border-color: #2196f3;

            outline: none;

            box-shadow: 0 0 5px rgba(33, 150, 243, 0.5);

        }


        button {

            background: #4caf50;

            color: #fff;

            border: none;

            padding: 10px 20px;

            font-size: 1em;

            border-radius: 4px;

            cursor: pointer;

            transition: background 0.3s ease;

        }


        button:hover {

            background: #45a049;

        }


        pre {

            background: #f1f1f1;

            padding: 10px;

            border-radius: 4px;

            overflow-x: auto;

            white-space: pre-wrap;

            word-wrap: break-word;

            border: 1px solid #ddd;

        }


        .error {

            color: #e53935;

            font-weight: bold;

        }

    </style>

</head>

<body>

    <header>

        <h1>JSON to Text Tool</h1>

    </header>

    <main>

        <div class="input-section">

            <label for="json-input">Enter JSON:</label>

            <textarea id="json-input" placeholder="Paste your JSON here..."></textarea>

        </div>

        <button id="convert-btn">Convert to Text</button>

        <div class="output-section">

            <label for="text-output">Resulting Text:</label>

            <pre id="text-output">Your output will appear here...</pre>

        </div>

    </main>


    <script>

        document.getElementById('convert-btn').addEventListener('click', () => {

            const jsonInput = document.getElementById('json-input').value;

            const textOutput = document.getElementById('text-output');


            try {

                const parsedJSON = JSON.parse(jsonInput);

                const formattedText = JSON.stringify(parsedJSON, null, 2);

                textOutput.textContent = formattedText;

                textOutput.classList.remove('error');

            } catch (error) {

                textOutput.textContent = 'Invalid JSON! Please check your input.';

                textOutput.classList.add('error');

            }

        });

    </script>

</body>

</html>


Admin

A Software Engineer, Social Media Marketing Expert, writer,

Post a Comment

Previous Post Next Post