A small, offline VS Code extension for inspecting structured data embedded inside other structured data. It finds XML stored in JSON values and JSON stored in XML text, CDATA, or attributes, then opens a separate, syntax-highlighted preview. The source document is never modified.
Why this extension?
Application logs and integration payloads often contain multiple serialization layers, for example:
- A JSON response with XML inside
Properties.Message.
- An XML message whose
<Payload> element contains JSON.
- XML or JSON values containing another embedded XML/JSON string.
- JSON serialized with escaped quotes (
{\"ReasonCode\":\"\"}) or XML entities (").
The extension lets you inspect those inner payloads without manually copying, unescaping, or changing the original data.
Commands
Open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) and run one of these commands:
| Command |
Run it while |
What it does |
| Embedded JSON/XML Formatter: Preview Embedded XML |
A JSON document is active |
Scans nested JSON objects and arrays for XML string values. Select a result to open formatted XML in a read-only preview tab. |
| Embedded JSON/XML Formatter: Preview Embedded JSON |
An XML document is active |
Scans XML text nodes, CDATA sections, and attribute values for JSON objects or arrays. Select a result to open formatted JSON in a read-only preview tab. |
There is intentionally no general Format Document command. This extension is designed for locating and previewing embedded payloads, not replacing the editor's normal document formatter.
Examples
XML embedded in JSON
Input JSON:
{
"Properties": {
"Message": "<Envelope><Payload><Id>123</Id></Payload></Envelope>"
}
}
Run Embedded JSON/XML Formatter: Preview Embedded XML. The picker identifies the source as Properties.Message. Choose it to open a formatted XML preview beside the JSON document.
Raw JSON embedded in XML
Input XML:
<Envelope>
<Payload>{"ReasonCode":"","InheritedReasonCode":false}</Payload>
</Envelope>
Run Embedded JSON/XML Formatter: Preview Embedded JSON. The picker shows the XML location, such as Envelope/Payload/text()[1].
Escaped JSON embedded in XML
Input XML:
<data>{\"ReasonCode\":\"\",\"InheritedReasonCode\":false}</data>
The extension decodes escaped JSON string content before parsing it, then opens a normal formatted JSON preview.
JSON encoded with XML entities
<data>{"ReasonCode":"","InheritedReasonCode":false}</data>
Predefined XML entities and decimal/hex numeric character references are decoded before JSON parsing.
Source paths and nested previews
The preview picker displays the location where each embedded value was found. For JSON-to-XML previews, this is the JSON property path (for example, Properties.Message). For XML-to-JSON previews, it is the XML element/text or attribute path (for example, Envelope/Payload/text()[1] or Envelope/Payload/@data).
When you open an embedded XML preview from a JSON property and then run Preview Embedded JSON inside that XML preview, the picker carries the original JSON property path forward and appends the XML location. This makes it clear both which outer field the payload came from and where the inner JSON was found.
Preview tabs are read-only virtual documents. They are separate from the original file, and closing a preview does not affect the source.
Supported embedded JSON locations
- XML element text nodes.
- CDATA sections.
- Quoted XML attribute values.
- Raw JSON objects and arrays.
- JSON with escaped quote characters.
- JSON using XML predefined entities (
&, <, >, ", ') and numeric character references (&#...;, &#x...;).
The scanner ignores invalid JSON candidates rather than stopping the entire scan. It expects meaningful XML structure; it is a conservative scanner, not a full validating XML parser. Custom DTD entity declarations are not expanded.
Settings
Open VS Code Settings and search for Embedded JSON/XML Formatter.
| Setting |
Default |
Description |
embeddedJsonXmlFormatter.indentSize |
2 |
Number of spaces used to indent formatted previews (1–8). |
embeddedJsonXmlFormatter.formatEmbeddedXml |
true |
Recursively format XML strings found inside JSON values shown in a JSON preview. |
embeddedJsonXmlFormatter.formatEmbeddedJson |
true |
Recursively format JSON strings found inside JSON values shown in a JSON preview. |
embeddedJsonXmlFormatter.maxDepth |
12 |
Maximum recursion depth when formatting nested JSON values (1–50). |
embeddedJsonXmlFormatter.xmlInlineText |
true |
Keep simple XML text-only elements on one line in formatted XML previews. |
Privacy and dependencies
- Runs locally in VS Code; no network requests or external services.
- No runtime dependencies.
- Does not edit, save, or overwrite the original document.
- Preview documents use a private extension URI scheme and are read-only.
Known limitations
- JSON candidates must be complete objects or arrays. Malformed or incomplete JSON is ignored.
- The XML scanner supports predefined and numeric character references, but does not expand custom DTD entities.
- The XML tokenizer checks basic tag nesting but is not a complete XML standards validator. It does not validate namespace bindings, DTD validity, or every XML character/entity constraint.
- Mixed XML content (text interspersed with child elements) is preserved inline to avoid introducing whitespace that could change text content.
- The extension scans valid XML structure; malformed XML may prevent reliable path discovery.
- JSONC comments and trailing commas are not supported because embedded JSON is parsed as standard JSON.
Development
Requires Node.js 18 or newer.
npm test
Run the extension locally by opening the project folder in VS Code and pressing F5 to launch an Extension Development Host. Package a VSIX with:
npx @vscode/vsce package
Install the resulting .vsix from Extensions: Install from VSIX....