-
-
Notifications
You must be signed in to change notification settings - Fork 0
Conventions
A35G edited this page Sep 10, 2026
·
1 revision
These four rules are the core of the library: once you understand them, you already know how to use it well. They apply in both directions (JSON → XML and XML → JSON).
{ "name": "Mario" }<name>Mario</name>{
"request": {
"@code": "",
"@typeReq": "ABC",
"customer": "Mario Rossi"
}
}<request code="" typeReq="ABC">
<customer>Mario Rossi</customer>
</request>Used when a node has both attributes and text (so-called mixed content):
{ "areaCode": { "@codeArea": "XXX", "#text": "contains <tag>" } }<areaCode codeArea="XXX"><![CDATA[contains <tag>]]></areaCode>A JSON array becomes a series of nodes with the same name, one per element, without an intermediate wrapper tag:
{ "Notes": { "Note": [ {"Main": "0"}, {"Main": "1"} ] } }<Notes>
<Note><Main>0</Main></Note>
<Note><Main>1</Main></Note>
</Notes>There is no key to "force" CDATA: the library decides on its own based on the content. A value only ends up in CDATA if it contains one of the characters < > & ' " or a newline.
{ "description": "Text with special <tag>" }<description><![CDATA[Text with special <tag>]]></description>{ "vatNumber": "12345678901" }<vatNumber>12345678901</vatNumber>If you never want CDATA, pass useCdata: false to the JsonToXmlConverter constructor.
⬅️ Previous page: Basic-Usage · ➡️ Next page: Round-Trip-and-Limitations