I'm trying to upload a CRX content package including that includes JSON data to AEM, but am hitting an error.
At the moment, I'm simply trying to create an empty JSON object under a page, to prove out the structure of my XML file.
The structure of the .content.xml
file in my package looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root jcr:primaryType="cq:Page">
<jcr:content jcr:primaryType="cq:PageContent">
<data jcr:primaryType="nt:file">
<jcr:content
jcr:primaryType="nt:resource"
jcr:mimeType="application/json"
jcr:data="{}"/>
</data>
</jcr:content>
</jcr:root>
I've entity encoded the braces (i.e. {}
) in the jcr:data
property to try and avoid hitting encoding issues on import. The error I'm getting is:
E /path/to/node (org.xml.sax.SAXException: unknown type:
java.lang.IllegalArgumentException: unknown type: )
Even though the JCR uses HTML entities as a means to escape special characters, SAX itself is decoding the entities before that, and hitting an issue when trying to parse the data.
SAX recognises curly braces as special characters which define a type (regardless of whether or not their encoded as HTML entities).
The reason the error message seems empty is because the JSON object itself is empty, e.g. if the JSON data were {hello world}
, the error returned would be unknown type: hello world
.
To resolve the issue, the braces need to be escaped with a backslash even when HTML entities are used, e.g. both:
jcr:data="\{\}"
or
jcr:data="\{\}"
Will work correctly.