Dynamic JSON Editor based in HTML/JavaScript

CK CK 3788 
Created at
Updated at  
510 0 0

JSON, or JavaScript Object Notation, is a lightweight, human-readable data-interchange format that uses a text-based structure derived from JavaScript syntax to represent data as key-value pairs and ordered lists. It is commonly used for transmitting data between a server and a web application, as well as for configuration files and data storage due to its simplicity, platform independence, and ease of parsing.
 

The following is an example of JSON:

{
  "Title": "My First JSON File",
  "Author": "Chun Kang",
  "Description": "This is a longer description that will appear in a <textarea> input because it exceeds 50 characters.",
  "Version": "1.0.0",
  "License": "MIT"
}

Below is nested JSON Example

{
  "Title": "Nested Example",
  "Author": {
    "Name": "Chun Kang",
    "Email": "chun@example.com"
  },
  "Tags": ["editor", "json", "example"],
  "Metadata": {
    "Created": "2025-07-27",
    "Modified": "2025-07-27"
  }
}

 

The below HTML/JavaScript code enables you to edit JSON file:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Nested JSON Editor (Textarea Only)</title>
  <style>
    body { font-family: sans-serif; padding: 20px; }
    .field { margin-bottom: 12px; }
    .key { font-weight: bold; display: block; margin-bottom: 4px; }
    textarea {
      width: 100%;
      min-height: 30px;
      padding: 6px;
      font-size: 14px;
      resize: vertical;
    }
    .object, .array {
      margin-left: 20px;
      border-left: 2px solid #ccc;
      padding-left: 10px;
      margin-bottom: 10px;
    }
    button {
      margin-top: 20px;
      padding: 8px 12px;
    }
  </style>
</head>
<body>

<h2>Edit Nested JSON (All Textareas)</h2>
<input type="file" id="fileInput" accept=".json"><br><br>
<div id="jsonEditor"></div>
<button onclick="downloadJson()">Download Edited JSON</button>

<script>
  let jsonData = {};

  document.getElementById('fileInput').addEventListener('change', function(event) {
    const file = event.target.files[0];
    if (!file) return;

    const reader = new FileReader();
    reader.onload = function(e) {
      try {
        jsonData = JSON.parse(e.target.result);
        const container = document.getElementById('jsonEditor');
        container.innerHTML = '';
        renderEditor(container, jsonData);
      } catch (err) {
        alert('Invalid JSON.');
      }
    };
    reader.readAsText(file);
  });

  function renderEditor(container, obj, path = '') {
    for (let key in obj) {
      const fullPath = path ? `${path}.${key}` : key;
      const value = obj[key];
      const field = document.createElement('div');
      field.className = 'field';

      const label = document.createElement('label');
      label.className = 'key';
      label.textContent = key;

      if (typeof value === 'object' && value !== null) {
        field.appendChild(label);
        const childContainer = document.createElement('div');
        childContainer.className = Array.isArray(value) ? 'array' : 'object';
        renderEditor(childContainer, value, fullPath);
        field.appendChild(childContainer);
      } else {
        const textarea = document.createElement('textarea');
        textarea.value = value;
        textarea.oninput = () => {
          setValueByPath(jsonData, fullPath, parseInput(textarea.value));
        };

        field.appendChild(label);
        field.appendChild(textarea);
      }

      container.appendChild(field);
    }
  }

  function setValueByPath(obj, path, value) {
    const keys = path.split('.');
    let temp = obj;
    for (let i = 0; i < keys.length - 1; i++) {
      temp = temp[keys[i]];
    }
    temp[keys[keys.length - 1]] = value;
  }

  function parseInput(value) {
    if (value === 'true') return true;
    if (value === 'false') return false;
    if (!isNaN(value) && value.trim() !== '') return Number(value);
    return value;
  }

  function downloadJson() {
    const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(jsonData, null, 2));
    const a = document.createElement('a');
    a.setAttribute('href', dataStr);
    a.setAttribute('download', 'edited_nested.json');
    a.click();
  }
</script>

</body>
</html>

 

The actual editing screen will be like below:

Dynamic JSON Editor based in HTML/JavaScript

 

If you want to have the full source code and example, please download at json editor_based in HTML5.zip

Tags JSON JSON Editor JavScript Object Notation Facebook X
Comments 0
Similar posts
  1. Recommended Vector DB Structure for Amazon Bedrock Integration
    389
  2. Save clustering result (aka dictionary) in JSON and Reuse loaded result
    378
  3. JSON format control in PHP
    691
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    39
  2. Tailwind CSS and shadcn/ui for React App with Charts and Graphs
    1,041
  3. HTML NoIndex: Keep Pages Off Search
    1,492
  4. JavaScript to disable Screen Saver or Power Saving Mode
    501
  5. Improving SEO with image-sitemap
    1,178
  6. Making HTML Tables Responsive on Mobile: Addressing Text Overflow
    774
  7. How do we make better SEO with schema.org?
    424
  8. A Javascript code that returns Monthly Mortgage Payment and Tax
    1,254
  9. A simple JavaScript snippet to copy a string to the clipboard
    1,051
  10. How to post content (image or video) to Instagram using the Instagram Graph API
    6,395
  11. Font name correctly having the same width space
    1,214
  12. JavaScript Algorithms
    717
  13. GraphQL Tutorial on CentOS 7: From Installation to Deployment
    556
  14. Capture all browser console logs including errors for debugging
    2,172
  15. Simple asynchronous/synchronous $.ajax() example using jQuery to make an HTTP GET request
    848
  16. JavaScript Code to Get Page Keywords
    347
  17. What is OpenGraph?
    366
  18. What is Twitter Cards?
    402
  19. Code to Extract the Site Thumbnail Image for Twitter or Facebook
    390
  20. JavaScript Code to Get the Page Title
    334
  21. JavaScript Code to Get Meta Description from HTML
    394
  22. Javascript code to extract favicon URL
    396
  23. RSS to Array in JavaScript
    2,149
  24. Javascript function to convert sitemap.xml to array
    598
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    39
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    34
  3. How do I create animated background for Google Meet?
    20,611
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    244
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    157
  7. Array of arguments passed to script in PHP
    90
  8. Invalid Auction Storms in Ad Tech
    98
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  10. The Two Clocks of Ad Server Architecture
    70
  11. Frequency Cap Architecture Overview
    514
  12. Collecting Proof-of-Play from 100,000 Screens
    146
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    287
  14. What is RedisVL?
    109
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    230
  16. TPU & GPU Cluster Management Tools
    243
  17. The Concept of Scaffolding in AI Agents
    233
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    583
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    258
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  22. Machine Learning: Training vs. Ranking
    221
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  25. Designing a Data Curation System Around a Vector Database
    220
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    256
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    195
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    216
  30. Understanding Data Lineage
    260