JSON String Converter VSCode ExtensionA powerful VSCode extension for detecting and converting JSON format text. Convert via shortcut
|
Command | Shortcut | Description |
---|---|---|
jsonstr.checkSelectedText |
Ctrl+Shift+T |
Check if selected text is JSON |
jsonstr.convertJson |
Right-click menu | Convert JSON format |
jsonstr.toggleAutoDetection |
Right-click menu | Toggle auto-detection mode |
Error Handling
The extension includes comprehensive error handling:
- Detect invalid JSON formats
- Provide friendly error messages
- Safe conversion operations to avoid data loss
Technical Implementation
- Developed with TypeScript for type safety
- Based on VSCode Extension API
- Includes complete JSON utility function library
- Supports detection and conversion of various JSON formats
Development
Project Structure
src/
├── extension.ts # Main extension file
├── json-utils.ts # JSON utility functions
├── HelloWorldPanel.ts # WebView panel
└── getNonce.ts # Utility functions
Compile and Test
# Compile extension
npm run compile
# Package extension
npm run package
# Run tests
npm test
🔧 Configuration Options
Auto-detection Mode
- Setting:
jsonstr.autoDetection
- Default:
true
- Function: Automatically detect JSON format and popup when text is selected
Preserve Indentation
- Setting:
jsonstr.preserveIndentation
- Default:
true
- Function: Preserve original indentation structure during conversion
Show Notification Messages
- Setting:
jsonstr.showNotifications
- Default:
true
- Function: Show notification messages for successful conversions
🎛️ Usage Modes
Silent Mode
If you don't want the extension to automatically popup:
- Disable auto-detection:
"jsonstr.autoDetection": false
- Disable notifications:
"jsonstr.showNotifications": false
- Still can use shortcuts for manual conversion
Preserve Format Mode
If your project has specific indentation standards:
- Enable preserve indentation:
"jsonstr.preserveIndentation": true
- Extension will analyze and maintain original JSON indentation structure
Standard Format Mode
If you want all JSON to use standard format:
- Disable preserve indentation:
"jsonstr.preserveIndentation": false
- All converted JSON will use 2-space indentation
📋 Setting Methods
Through Settings Interface
- Press
Cmd+,
(Mac) orCtrl+,
(Windows/Linux) to open settings - Search for "jsonstr"
- Find and modify related settings
Through Command Palette
- Press
Cmd+Shift+P
(Mac) orCtrl+Shift+P
(Windows/Linux) - Enter "Preferences: Open Settings (JSON)"
- Add configuration in settings.json
Through Right-click Menu
- Right-click in editor and select "Toggle auto-detection mode"
For detailed settings instructions, please refer to SETTINGS.md
License
This project is licensed under the CC0 1.0 Universal License - see the LICENSE file for details.
CC0 1.0 Universal is the most permissive license available. It dedicates the work to the public domain by waiving all of the author's rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.
You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.