A powerful VS Code extension that automatically formats XML-escaped JSON in Salesforce CustomMetadata files. Edit JSON in a readable format with automatic conversion to XML on save.
Features
✨ Automatic JSON Formatting on Open
- XML files are automatically formatted to display readable JSON when opened
- No keyboard shortcuts needed - just open the file and see formatted JSON
- Works seamlessly with Salesforce CustomMetadata XML files
💾 Transparent Save-to-XML Conversion
- Edit JSON in the editor (formatted and readable)
- When you save, the JSON is automatically converted back to escaped XML
- The file always saves in XML format for Salesforce compatibility
- You always see the JSON version - the conversion is transparent
🎯 Smart Field Detection
- Automatically identifies JSON fields (e.g.,
XRL__JSON__c)
- Preserves non-JSON fields unchanged
- Handles multiple JSON fields in a single file
🔧 Production-Ready
- Non-destructive formatting (only formats JSON fields)
- Comprehensive error handling with clear messages
- Lightweight with zero external dependencies
🚀 Developer Friendly
- Works with any XML structure (not limited to Salesforce)
- Supports deeply nested JSON objects
- 2-space indentation for clean formatting
Installation
From VS Code Marketplace
- Open Extensions in VS Code (
Ctrl+Shift+X / Cmd+Shift+X)
- Search for "Salesforce XML JSON Formatter"
- Click Install
Usage
Quick Start
- Open an XML file in VS Code
- JSON automatically formats - no action needed
- Edit the JSON in the formatted view
- Save the file (Ctrl+S / Cmd+S) - automatically converts to escaped XML
- Continue editing - JSON view is restored after save
Optional at any time:
- Press
Alt+J to manually format JSON (useful if changes aren't detected automatically)
- Press
Alt+X to manually escape JSON back to XML format
How It Works
On File Open:
- Extension detects XML files with JSON fields
- Automatically formats all JSON to be readable and properly indented
- You see formatted JSON in the editor
On File Save:
- Extension converts formatted JSON back to escaped XML
- Saves the XML-escaped version to disk (Salesforce-compatible)
- Re-applies JSON formatting so you continue seeing JSON
- Result: JSON in editor, XML on disk
You can also manually trigger formatting or unformatting at any time:
| Action |
Windows/Linux |
macOS |
| Format to JSON |
Alt+J |
Alt+J |
| Escape to XML |
Alt+X |
Alt+X |
Example
Before:
<values>
<field>XRL__JSON__c</field>
<value xsi:type="xsd:string">{"executors":[],"orchestrator":{"successResult":{"isWriteSuccessToLog":false,"successTemplate":"$Label.Success"},"childSOQL":"SELECT Id FROM Account"}}</value>
</values>
After (Press Alt+J):
<values>
<field>XRL__JSON__c</field>
<value xsi:type="xsd:string">{
"executors": [],
"orchestrator": {
"successResult": {
"isWriteSuccessToLog": false,
"successTemplate": "$Label.Success"
},
"childSOQL": "SELECT Id FROM Account"
}
}</value>
</values>
Supported File Types
- Primary: Salesforce CustomMetadata XML files (
.md-meta.xml)
- Secondary: Any XML file with JSON fields
Commands
Command ID: xmltoJSON.formatJson
Manually format all JSON fields in the current XML file to display readable, indented JSON.
Keyboard Shortcut: Alt+J
Command ID: xmltoJSON.unformatJson
Manually convert formatted JSON back to escaped XML in the current file. Useful if you want to escape JSON without saving.
Keyboard Shortcut: Alt+X
Automatic Features
- Auto-Format on Open: Triggered when you open an XML file (no shortcut needed)
- Auto-Escape on Save: Triggered when you save an XML file with formatted JSON (no shortcut needed)
How Data is Stored vs. Displayed
| State |
What You See |
What's Saved |
| File Opened |
Formatted, readable JSON |
N/A (just opened) |
| While Editing |
Formatted, readable JSON |
N/A (not saved yet) |
| After Save |
Formatted, readable JSON |
Escaped XML (Salesforce format) |
| File Reopened |
Formatted, readable JSON |
Escaped XML on disk |
This design ensures maximum readability while maintaining Salesforce compatibility.
Configuration
Currently, the extension uses default settings:
- 2-space indentation for formatted JSON
- Automatic formatting on file open (no option to disable yet)
- Automatic XML conversion on save (no option to disable yet)
Future versions may support:
- Custom indentation size
- Compact vs. expanded formatting
- Toggle for automatic formatting and saving
- Selective field filtering
Troubleshooting
❌ "This command only works with XML files"
Solution: Ensure your file has XML language mode enabled.
- Check: Bottom-right corner should show "XML"
- If not: Click the language selector and choose "XML"
❌ "No JSON fields found in this XML file"
Solution: Verify your XML contains JSON field values.
- Check that fields contain valid JSON (not plain strings)
- Ensure JSON is properly enclosed in XML value tags
❌ Extension not activating
Solution: Make sure you have an XML file open.
- The extension auto-activates when you open an
.xml file
- Check VS Code Output panel for debug messages
⚠️ "Could not find replaceable JSON fields"
Solution: JSON parsing failed. Verify:
- JSON syntax is valid (all quotes/braces matched)
- No circular references in JSON
- All special characters are properly escaped in XML
- Ensure the file is recognized as XML (check language mode in bottom-right)
- Verify the file contains valid JSON in XML-escaped format
- Check the VS Code Output panel for error messages
File Not Converting to XML on Save
- Ensure the JSON is properly formatted (multiple lines with indentation)
- Check that JSON is valid (no syntax errors)
- Review console logs for detailed error information
- Extension size: ~50 KB (uncompressed)
- Memory footprint: Minimal (<5 MB typical)
- Processing time: <100ms for files up to 100 KB
- Tested with: 87 real Salesforce CustomMetadata files
Known Limitations
- Only formats JSON fields (pure string fields are preserved as-is)
- Cannot handle malformed JSON (validation errors are caught and reported)
- Auto-formatting on open happens silently (no notification shown)
- Auto-escaping on save may add a slight delay to the save operation (~100-200ms for typical files)
Privacy & Security
- ✅ No telemetry or usage tracking
- ✅ No network calls
- ✅ All processing is local (no data leaves your machine)
- ✅ Open source (MIT license) - code is fully transparent
Changelog
See CHANGELOG.md for version history and release notes.
License
MIT License - see LICENSE file for details.
Made with ❤️ for Salesforce developers