CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jsoneditor

A web-based tool to view, edit, format, and validate JSON with multiple editing modes including tree, code, text, and preview

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

preview-mode.mddocs/

Preview Mode

Read-only preview mode designed for handling large JSON documents up to 500 MiB with optimized performance, transformation capabilities, and minimal memory usage.

Capabilities

Large Document Handling

Preview mode is specifically designed to handle very large JSON documents that would be impractical in other modes.

// Preview mode configuration for large documents
const previewOptions = {
  mode: "preview",
  enableTransform: true,    // Enable JMESPath transformations
  enableSort: false,        // Disable sorting for performance
  search: false,           // Search disabled for large documents
  mainMenuBar: true,       // Show format/transform controls
  statusBar: true          // Show document size and statistics
};

Features:

  • Memory Efficient: Optimized rendering for documents up to 500 MiB
  • Read-Only: No editing capabilities to maintain performance
  • Transform Support: JMESPath queries and data filtering
  • Format/Compact: JSON formatting and compacting
  • Repair: Automatic JSON repair functionality

Execute with Busy Message

Execute operations with user feedback for long-running tasks on large datasets.

/**
 * Execute a function with a busy message for long operations
 * @param fn - Function to execute
 * @param message - Message to show during execution
 * @returns Promise resolving to function result
 */
executeWithBusyMessage(fn: () => any, message: string): Promise<any>;

Usage Example:

// Execute expensive operation with user feedback
const result = await editor.executeWithBusyMessage(
  () => {
    // Perform expensive transformation
    const largeData = editor.get();
    return processLargeDataset(largeData);
  },
  "Processing large dataset..."
);

// Transform large JSON with progress indication
await editor.executeWithBusyMessage(
  () => editor.setText(transformedJsonString),
  "Applying transformation to large document..."
);

Format Large JSON

Format large JSON documents with progress indication for better user experience.

/**
 * Format JSON text with progress indication for large documents
 * Inherited from text mode functionality
 */
format(): void;

Usage Example:

// Format large JSON - automatically shows progress for large documents
editor.format();

// For very large documents, this may trigger executeWithBusyMessage internally

Compact Large JSON

Remove whitespace from large JSON documents efficiently.

/**
 * Compact JSON text by removing whitespace
 * Optimized for large documents
 */
compact(): void;

Usage Example:

// Compact large JSON document
editor.compact();

// This operation is optimized for large documents
// and may show progress indication

Repair Large JSON

Attempt to repair invalid JSON in large documents.

/**
 * Repair invalid JSON syntax in large documents
 * Uses progressive parsing for better performance
 */
repair(): void;

Usage Example:

// Repair large invalid JSON document
editor.repair();

// The repair process is optimized for large files
// and shows progress for operations taking longer than expected

Preview Mode Features

Document Statistics

Preview mode shows comprehensive document statistics in the status bar:

// Information displayed in preview mode:
// - Document size (bytes, KB, MB)
// - JSON structure overview (objects, arrays, primitives)
// - Parse time and render time
// - Memory usage statistics

Performance Optimizations

Preview mode includes several optimizations for large documents:

Lazy Loading:

  • Content is rendered progressively as needed
  • Only visible portions are fully processed
  • Off-screen content uses lightweight placeholders

Memory Management:

  • Efficient memory usage for large datasets
  • Garbage collection optimizations
  • Memory usage monitoring and warnings

Progressive Operations:

  • Long operations are broken into chunks
  • User interface remains responsive during processing
  • Progress indication for operations > 100ms

Transform Large Datasets

Apply JMESPath transformations to large JSON documents efficiently.

// Transform configuration for large documents
const transformOptions = {
  mode: "preview",
  enableTransform: true,
  
  // Custom query functions optimized for large data
  executeQuery: (json, query) => {
    // Custom implementation with progress tracking
    return executeQueryWithProgress(json, query);
  },
  
  queryDescription: "JMESPath transformations optimized for large datasets"
};

Usage Example:

// Transform large dataset with progress indication
const largeDataEditor = new JSONEditor(container, {
  mode: "preview",
  enableTransform: true
});

// Load large JSON
largeDataEditor.setText(largeJsonString);

// Transformations automatically use busy messages for large operations
// User can filter, sort, and project data through the Transform modal

Preview Mode Limitations

Read-Only Nature

  • No Editing: Values, keys, and structure cannot be modified
  • No Undo/Redo: History functionality is disabled
  • No Schema Validation: Validation is disabled for performance

Feature Restrictions

  • No Search: Text search is disabled for performance reasons
  • Limited Selection: Node selection is not available
  • No Context Menus: Right-click menus are disabled

Performance Considerations

  • Memory Usage: Very large documents (>100MB) may still impact browser performance
  • Transform Complexity: Complex JMESPath queries on large datasets may be slow
  • Browser Limits: Ultimate size limits depend on browser memory capabilities

Preview Mode Configuration

Basic Configuration

const previewConfig = {
  mode: "preview",
  
  // Enable/disable transform features
  enableTransform: true,
  enableSort: false,
  
  // UI components
  mainMenuBar: true,    // Show Transform/Format buttons
  statusBar: true,      // Show document statistics
  navigationBar: false, // Navigation disabled in preview
  
  // Text formatting
  indentation: 2,       // Spaces for formatting
  escapeUnicode: false  // Unicode display
};

Large Document Optimization

const largeDocConfig = {
  mode: "preview",
  
  // Optimize for large documents
  enableTransform: true,  // Keep transforms enabled
  enableSort: false,      // Disable sorting for performance
  search: false,         // Disable search
  
  // Custom progress handling
  onError: (error) => {
    if (error.message.includes('memory')) {
      showMemoryWarning();
    }
  }
};

Memory Monitoring

// Monitor memory usage in preview mode
const previewEditor = new JSONEditor(container, {
  mode: "preview",
  
  // Handle memory warnings
  onError: (error) => {
    if (error.name === 'MemoryWarning') {
      console.warn('Large document detected:', error.message);
      showPerformanceWarning();
    }
  }
});

// Check document size before loading
function loadLargeDocument(jsonString) {
  const sizeInMB = new Blob([jsonString]).size / (1024 * 1024);
  
  if (sizeInMB > 100) {
    console.warn(`Loading ${sizeInMB.toFixed(1)}MB document`);
    
    // Use preview mode for large documents
    previewEditor.setText(jsonString);
  }
}

Best Practices for Preview Mode

When to Use Preview Mode

// Use preview mode when:
// 1. Document size > 10MB
// 2. Read-only access is sufficient
// 3. Transform/filter operations are needed
// 4. Memory usage is a concern

function chooseMode(jsonString) {
  const size = new Blob([jsonString]).size;
  const sizeMB = size / (1024 * 1024);
  
  if (sizeMB > 10) {
    return "preview"; // Large documents
  } else if (sizeMB > 1) {
    return "code";    // Medium documents
  } else {
    return "tree";    // Small documents
  }
}

Performance Tips

// 1. Minimize transformations on very large datasets
// 2. Use specific JMESPath queries rather than broad selections
// 3. Consider pre-processing large documents server-side
// 4. Monitor memory usage in browser dev tools

// Good: Specific query
const specificQuery = "users[?age > 25].{name: name, email: email}";

// Avoid: Broad query on large dataset
const broadQuery = "users[]"; // Returns entire large array

docs

configuration.md

editor-core.md

index.md

mode-management.md

preview-mode.md

schema-validation.md

text-operations.md

transform-operations.md

tree-operations.md

tile.json