---
title: Base64-decode XML from JSON with a Liquid Stylesheet
description: Decode base64-encoded XML embedded in JSON messages and render it as readable XML in Nodinite Log Views using a Liquid stylesheet with JavaScript.
---

# Base64-decode XML from JSON with a Liquid Stylesheet

Decode base64-encoded XML embedded in JSON messages and render it as readable XML in <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> [Log Views][]. This Liquid-based [Stylesheet][] enables operators to preview, inspect, and download XML content directly—no additional tooling required.

Benefits:

* ✅ View embedded XML inline without external tools  
* ✅ Decode base64 client-side for fast previews and diagnostics  
* ✅ Export rendered XML for sharing or offline analysis  

![Base64-decode the order XML from a Service Bus JSON message with a Liquid Stylesheet in a Log View, animated walkthrough (7.12)][1]  
*Animated walkthrough: **View message body** shows the JSON with the base64 text in `body.ContentData`; **View message formatted as** the Stylesheet shows the decoded order XML, `å` included, in a code editor.*  

<div class="mermaid">
graph LR
    Json["fa:fa-file-code JSON Message<br/>with base64-encoded XML"] --> stylesheet["fa:fa-droplet Liquid Stylesheet<br/>with JavaScript"]
    stylesheet -->|"Transform"| xml["fa:fa-file-lines Readable XML<br/>in the Log View"]
    style Json fill:#2678BD,color:#fff
    style stylesheet fill:#E47528,color:#fff
    style xml fill:#93d16d,color:#000
</div>

*The JSON input (blue) passes the Liquid Stylesheet (orange) and appears as readable XML (green). The [StylesheetScriptsEnabled][] [System Parameter][System Parameters] must be `true` for the JavaScript to run.*

This example demonstrates how to transform a JSON message containing base64-encoded XML into rendered XML output using a Liquid [Stylesheet][]. Use this approach to make data accessible to end-users while optionally removing sensitive information.

## 1. Input JSON

The following data is an example of a JSON message with a base64 encoded content:

```json
{
	"method": "post",
	"queries": {
		"systemProperties": "Run Details"
	},
	"path": "/orders/messages",
	"host": {
		"connection": {
			"name": "/subscriptions/ae3da538-3e2b-4490-9feb-7dfe30a6683c/resourceGroups/Default-Storage-NorthEurope/providers/Microsoft.Web/connections/servicebus"
		}
	},
	"body": {
		"ContentData": "PG5zMDpPcmRlcnMgeG1sbnM6bnMwPSJTdXBwbHlDaGFpbi5TY2hlbWFzLzEuMCI+CiAgPE9yZGVyPgogICAgPElkPjEzMzc8L0lkPgogICAgPEFtb3VudD4xMzM3PC9BbW91bnQ+CiAgICA8Q2l0eT5Ta2VsbGVmdGXDpTwvQ2l0eT4KICA8L09yZGVyPgo8L25zMDpPcmRlcnM+",
		"CorrelationId": "BOWC123",
		"Properties": {
			"ExtendedProperties/1.0#SystemInterchangeId": "BOWC123"
		}
	}
}
```

## 2. Liquid Stylesheet

Use a Liquid [Stylesheet][] to decode and render the base64-encoded XML content.

<aside aria-label="Warning" class="nodinite-note nodinite-note--warning">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-triangle-exclamation"></i> Warning</p>
<div class="nodinite-note__content"><p><strong>Script Execution Requirement:</strong> This stylesheet contains embedded JavaScript code. The <a href="https://docs.nodinite.com/administration/settings/system-parameters/stylesheetscriptsenabled/">StylesheetScriptsEnabled</a> system parameter <strong>must be set to <code>true</code></strong> for this stylesheet to execute. The default is <code>false</code> on a new installation; an upgraded installation keeps its value. Only members of the built-in <strong>Administrators</strong> role can enable this parameter. <sup><span class="nodinite-new-badge">New 7.12</span></sup> The script runs in an isolated frame and can't read the <a href="https://docs.nodinite.com/getting-started/overview/">Web Client's</a> page, cookies, or storage. See <a href="https://docs.nodinite.com/administration/settings/system-parameters/stylesheetscriptsenabled/">StylesheetScriptsEnabled</a> for security considerations.</p></div>
</aside>

<aside aria-label="Important" class="nodinite-note nodinite-note--important">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-message-exclamation"></i> Important</p>
<div class="nodinite-note__content"><p><strong>Configuration Required:</strong> Enable <strong>"Message Body is Json"</strong> in the Stylesheet settings. When enabled, <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> parses the JSON message and injects properties as Liquid variables, allowing you to access nested properties like <code>{{body['ContentData']}}</code> directly in your Liquid template. Without it, <code>{{body['ContentData']}}</code> is empty and nothing is decoded.</p></div>
</aside>

![Stylesheet settings with Type Liquid, Render as HTML and Message Body is Json checked, bound to the Message Type Contoso.ServiceBus.OrderEnvelope/1.0 (7.12)][2]  
*The Stylesheet's settings: Type **Liquid**, **Render as HTML** and **Message Body is Json** checked, and the [Message Type][Message Types] of the JSON messages under **Message Types**.*  

```Liquid
	<textarea rows="50" cols="50" style="border: none;outline: none;" id="demo"> </textarea>
	<pre id="demoprint" style="margin:0; padding:0; border:none; display:none;"></pre>
	<script>
		var editor;
		function codemirroreditor(elem) {
			var mime = 'application/xml';
			 editor = CodeMirror.fromTextArea(elem, {
				lineNumbers: true,
				mode: mime,
				indentWithTabs: true,
				smartIndent: true,
				lineNumbers: true,
				matchBrackets: true,
				lineWrapping: true,
				autofocus: true,
				autoRefresh: true,
				extraKeys: { "Ctrl-Space": "autocomplete" }
			});
		}

		function b64DecodeUnicode(str) {
			return decodeURIComponent(
				atob(str)
					.split('')
					.map(function(c) {
						return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
					})
					.join('')
				);
		}


		var content = b64DecodeUnicode("{{body['ContentData']}}");
		function displayXml() {
			var elem = document.getElementById('demo');
			elem.value = content;
			codemirroreditor(elem);
		};

		function htmlEntities(str) {
			var htmlString = String(str).replace(/&/g, '&amp;').replace(/</g,'&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
			return htmlString;
		}

		window.addEventListener('beforeprint', (event) => {
			$(editor.getWrapperElement()).hide();
			$("#demoprint").html(htmlEntities(content)).show();
		});

		window.addEventListener('afterprint', (event) => {
			$(editor.getWrapperElement()).show();
			$("#demoprint").hide();
		});

		displayXml();
		</script>

<style>
  html {height:calc(100vh - 200px); min-height:500px;}
  body {height:100%;}
  .CodeMirror {
    min-height: 200px;
    height: 100%;
  }
</style>
```

## 3. XML Output

Applying the Liquid [Stylesheet][] to the [Input JSON](#input-json) produces the following XML output:

```xml
<ns0:Orders xmlns:ns0="SupplyChain.Schemas/1.0">
  <Order>
    <Id>1337</Id>
    <Amount>1337</Amount>
    <City>Skellefteå</City>
  </Order>
</ns0:Orders>
```

In the [Log View][Log Views], **View message formatted as** the Stylesheet shows the same XML:

![View message body formatted as Contoso - Order XML from Service Bus envelope with the decoded order XML, Skelleftea with the Swedish a-ring included (7.12)][5]  
*The decoded order XML in the Log View.*  

<aside aria-label="Note" class="nodinite-note nodinite-note--note">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-note"></i> Note</p>
<div class="nodinite-note__content"><p>This example performs Unicode translation to properly handle special characters like "å" in the City field.</p></div>
</aside>

### Without Message Body is Json

Unticked, the JSON body reaches the template raw, as `{{data}}`, and `{{body['ContentData']}}` renders empty. **View message formatted as** the Stylesheet then shows an empty editor:

![The same Stylesheet settings with Message Body is Json unchecked (7.12)][3]  
*The Stylesheet with **Message Body is Json** unchecked.*  

![View message body formatted as Contoso - Order XML from Service Bus envelope with an empty editor (7.12)][4]  
*Unchecked: nothing to decode, so the editor stays empty.*  

## 4. Download Button

Add a download button to allow users to save the rendered XML content locally.

<aside aria-label="Warning" class="nodinite-note nodinite-note--warning">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-triangle-exclamation"></i> Warning</p>
<div class="nodinite-note__content"><p><strong>Script Execution Requirement:</strong> This enhanced stylesheet contains embedded JavaScript code. The <a href="https://docs.nodinite.com/administration/settings/system-parameters/stylesheetscriptsenabled/">StylesheetScriptsEnabled</a> system parameter <strong>must be set to <code>true</code></strong> for this stylesheet to execute (<code>false</code> is the default on a new installation). See <a href="https://docs.nodinite.com/administration/settings/system-parameters/stylesheetscriptsenabled/">StylesheetScriptsEnabled</a> for security considerations.</p></div>
</aside>

**Instructions:** Adjust the `CONTENTTYPE` and `FILENAME` variables in the code below to match your expected file type.

```Liquid
<button class="btn btn-success" id="downloadButton">Download</button>
<style>

  .btn {
      display: inline-block;
      font-weight: 400;
      color: #212529;
      text-align: center;
      vertical-align: middle;
      user-select: none;
      background-color: transparent;
      border: 1px solid transparent;
      padding: 0.375rem 0.75rem;
      font-size: 1rem;
      line-height: 1.5;
      border-radius: 0.25rem;
      transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
      box-sizing: border-box;
      margin: 1rem;
  }    

  .btn-success {
      color: #fff;
      background-color: #68a19b;
      border-color: #68a19b;
      box-shadow: inset 0 1px 0 rgb(255 255 255 / 15%), 0 1px 1px rgb(0 0 0 / 8%);
  }
  html {height:calc(100vh - 200px); min-height:400px;}
  body {height:100%;}
  .CodeMirror {
    min-height: 200px;
    height: calc(100%-40px);
  }
</style>

<textarea rows="50" cols="50" id="demo"></textarea>
<pre id="demoprint" style="margin:0; padding:0; border:none; display:none;"></pre>
<script>
(function() {
  ///// CHANGE THIS
  var CONTENTTYPE = "application/xml";
  var FILENAME = "out.xml";
  ////////////////


    var editor;
    function codemirroreditor(id) {
      var mime = 'application/xml';
      editor = CodeMirror.fromTextArea(
        document.getElementById(id), 
          {
                lineNumbers: true,
                mode: mime,
                indentWithTabs: true,
                smartIndent: true,
                lineNumbers: true,
                matchBrackets: true,
                lineWrapping: true,
                autofocus: true,
                autoRefresh: true,
                extraKeys: { "Ctrl-Space": "autocomplete" }
          }
        );
  }

  function b64DecodeUnicode(str) {
        return decodeURIComponent(atob(str).split('').map(function(c) {
            return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
        }).join(''));
  }
    var content = b64DecodeUnicode("{{ body['ContentData'] }}");
  function displayXml() {
    $("#demo").html(content);
    codemirroreditor('demo');
  };

    function htmlEntities(str) {
    var htmlString = String(str).replace(/&/g, '&amp;').replace(/</g,'&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
    return htmlString;
  }

    window.addEventListener('beforeprint', (event) => {
      $(editor.getWrapperElement()).hide();
        $("#demoprint").html(htmlEntities(content)).show();
    $("#downloadButton").hide();
    });

    window.addEventListener('afterprint', (event) => {
        $(editor.getWrapperElement()).show();
        $("#demoprint").hide();
    $("#downloadButton").show();
    });
  displayXml();

  function save(filename, data) {
    const blob = new Blob([data], {type: CONTENTTYPE});
    if(window.navigator.msSaveOrOpenBlob) {
      window.navigator.msSaveBlob(blob, filename);
    }
    else{
      const elem = window.document.createElement('a');
      elem.href = window.URL.createObjectURL(blob);
      elem.download = filename;        
      document.body.appendChild(elem);
      elem.click();        
      document.body.removeChild(elem);
    }
  }

  $("#downloadButton").click(() => { save(FILENAME, content) } ) 

})();
</script>
```

## Escaped XML

If your content is **not** base64-encoded and contains quotes (`"`), extract the content using template literals:

```liquid
var content = `{{body.content}}`;
```

### Escaped XML Example

```json
{
    "body": {
        "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Document Company=\"CONTOSO\\\" ExportType=\"FULL\">\n   <ENTITY ACTIVEDATE=\"\"\n BANKACCOUNTID=\"\"\n VENDORGROUPID=\"\"\n VENDORORGANIZATIONNAME=\"\"/>\n</Document>\n"
    }
}
```

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* <i class="fal fa-file-plus" aria-hidden="true"></i> [Add or manage Stylesheet][] – Install the Liquid stylesheet and test it with Preview  
* <i class="fal fa-gears" aria-hidden="true"></i> [StylesheetScriptsEnabled][] – Allow the embedded JavaScript to run  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-file-lines" aria-hidden="true"></i> [Stylesheets][] – Manage and customize stylesheets  
* <i class="fal fa-code" aria-hidden="true"></i> [Stylesheet Examples][] – All XSLT and Liquid examples  
* <i class="fal fa-file-lines" aria-hidden="true"></i> [Line break an EDIFACT][] – Another Liquid example with JavaScript  
* <i class="fal fa-bell" aria-hidden="true"></i> [Alarm Plugin Object][] – Transform alarm plugin payloads  
* <i class="fal fa-search" aria-hidden="true"></i> [Log Views][] – Create role-specific log views with custom stylesheets  
* <i class="fal fa-tags" aria-hidden="true"></i> [Message Types][] – Bind the Stylesheet to the Message Type of your JSON messages  
* <i class="fal fa-language" aria-hidden="true"></i> [Character Encoding][] – How <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span> decides the body encoding before the Stylesheet runs  

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Customize/Stylesheets/Stylesheet_Base64DecodeXml.gif
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Customize/Stylesheets/Stylesheet_Base64DecodeXml_Settings.png
[3]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Customize/Stylesheets/Stylesheet_Base64DecodeXml_SettingsUnticked.png
[4]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Customize/Stylesheets/Stylesheet_Base64DecodeXml_FormattedEmpty.png
[5]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Customize/Stylesheets/Stylesheet_Base64DecodeXml_Formatted.png

[Add or manage Stylesheet]:https://docs.nodinite.com/administration/customize/stylesheets/features/add-or-manage-stylesheet/
[Alarm Plugin Object]:https://docs.nodinite.com/administration/customize/stylesheets/examples/alarm-plugin-object/
[Character Encoding]:https://docs.nodinite.com/core-services/log-event/features/character-encoding/
[Line break an EDIFACT]:https://docs.nodinite.com/administration/customize/stylesheets/examples/line-break-an-edifact/
[Log Views]:https://docs.nodinite.com/administration/log-management/log-views/features/what-is-a-log-view/
[Message Types]:https://docs.nodinite.com/repository-model/message-types/overview/
[Stylesheet]:https://docs.nodinite.com/administration/customize/stylesheets/features/what-is-a-stylesheet/
[Stylesheet Examples]:https://docs.nodinite.com/administration/customize/stylesheets/examples/overview/
[Stylesheets]:https://docs.nodinite.com/administration/customize/stylesheets/features/what-is-a-stylesheet/
[StylesheetScriptsEnabled]:https://docs.nodinite.com/administration/settings/system-parameters/stylesheetscriptsenabled/
[System Parameters]:https://docs.nodinite.com/administration/settings/system-parameters/overview/
[Web Client]:https://docs.nodinite.com/getting-started/overview/