๐ Problem Statement
In a Real-Time REST integration in Oracle Integration Cloud, the source system sends Base64 encoded JSON.
Flow:
Receive Base64 payload
Decode using oraext:decodeBase64()
Pass to Stage File → Read as JSON
❗ Issue Faced
After decoding, the JSON becomes invalid because:
The closing curly brace } is missing
This causes NXSD parsing errors in Stage File
๐ Root Cause
During decoding or transformation:
Extra whitespace / formatting issues
Improper encoding at source
OIC string handling edge cases
๐ Result: JSON becomes malformed, especially missing }
๐ก Solution Approach
Instead of directly parsing decoded JSON:
✅ Step 1: Decode Base64
✅ Step 2: Clean the JSON string
✅ Step 3: Validate & fix missing closing brace
✅ Step 4: Re-encode to Base64
✅ Step 5: Pass as Opaque to Stage File
๐ ️ Implementation (XSLT Logic)
✅ Step 1: Decode Base64
Xslt
<xsl:variable name="decoded"
select="oraext:decodeBase64(/nssrcmpr:execute/ns16:request-wrapper/ns16:message)"/>
✅ Step 2: Clean unwanted whitespace
Xslt
<xsl:variable name="cleaned"
select="replace($decoded, '(:\s*")\s+', '$1')"/>
๐ Removes unnecessary spaces after : in JSON
✅ Step 3: Fix Missing Closing Brace
Xslt
<xsl:variable name="finalJson">
<xsl:choose>
<xsl:when test="contains($cleaned, '}')">
<xsl:value-of select="$cleaned"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($cleaned, '}')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
๐ Ensures JSON is always valid
✅ Step 4: Encode Back to Base64
Xslt
<xsl:value-of select="oraext:encodeBase64($finalJson)"/>
๐ Integration Flow Design
๐งฉ OIC Flow Steps
REST Trigger
Stage File (Write File)
Write as Opaque
Use above XSLT
Stage File (Read File)
Now JSON is valid
Parse using NXSD schema
Continue processing…
๐ฏ Why Opaque Handling Works
Using opaque avoids:
Early validation failures
NXSD parsing errors on invalid JSON
๐ You fix JSON before parsing
⚠️ Best Practices
Always validate decoded payload:
Use contains() or ends-with() for }
Log decoded payload (for debugging)
Avoid direct parsing of decoded Base64 without validation
๐ Conclusion
Handling Base64 JSON in OIC can be tricky due to:
Encoding inconsistencies
Transformation side effects
๐ The decode → clean → fix → re-encode → stage as opaque pattern is a reliable solution.
Code screenshots:
Stage write:
Read json:
Code snippet:
<xsl:template match="/" xml:id="id_11">
<nstrgmpr:Write xml:id="id_12">
<ns31:opaqueElement>
<!-- Step 1: Decode -->
<xsl:variable name="decoded" select="oraext:decodeBase64(/nssrcmpr:execute/ns16:request-wrapper/ns16:message)"/>
<!-- Step 2: Clean whitespace after ":" -->
<xsl:variable name="cleaned"
select="replace($decoded, '(:\s*")\s+', '$1')"/>
<!-- Step 3: Check and fix closing brace -->
<xsl:variable name="finalJson">
<xsl:choose>
<xsl:when test="contains($cleaned, '}')">
<xsl:value-of select="$cleaned"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($cleaned, '}')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Step 4: Encode back -->
<xsl:value-of select="oraext:encodeBase64($finalJson)"/>
</ns31:opaqueElement>
</nstrgmpr:Write>
</xsl:template>






























