> Markdown versions of all pages of this connector library are available by appending `.md` to the page URL. For the full index of connectors, see [llms.txt](https://connectors.appmixer.com/llms.txt).

# appmixer.utils.xml.XmlToJson

- Component: `appmixer.utils.xml.XmlToJson`
- Kind: Action
- Version: 1.0.0
- Visibility: Public
- Connector: [appmixer.utils.xml 1.0.8](https://connectors.appmixer.com/connector/appmixer.utils.xml/1.0.8.md)
- Component page: <https://connectors.appmixer.com/connector/appmixer.utils.xml/1.0.8/component/appmixer.utils.xml.XmlToJson>

Convert XML to JSON.

## Input ports

### Port `in`

| Field | Type | Description |
| --- | --- | --- |
| XML (`xml`) | textarea | XML text content to convert to JSON. |
| Allow Boolean Attributes (`allowBooleanAttributes`) | toggle | To allow attributes without value. <root checked></root> -> { "root": { "@checked": true } } |
| Always Create Text Node (`alwaysCreateTextNode`) | toggle | Instead of creating a property with the tag name and assign the value directly, create a #text node with the value. <root>foo</root> -> { "root": { "#text": foo } } |
| Attributes Group Name (`attributesGroupName`) | text | To group all the attributes of a tag under given property name. E.g. for "_@": <root a=foo b=bar></root> -> { "root": { "_@": { "a": "foo", "b": "bar" } } } |
| Attribute Name Prefix (`attributeNamePrefix`) | text | To recognize attributes in JSON separately. E.g. for "_@": <root a=foo><a>wow</a></root> -> { "root": { "a": "wow", "_@": "foo" } } |
| CDATA Property Name (`cdataPropName`) | text | If not set to some property name, then CDATA values are merged to tag's text value. E.g. for "$cdata": <name>name:<![CDATA[<some>Jack</some>]]><![CDATA[Jack]]></name> -> { "name": { "$cdata": ["<some>Jack</some>", "Jack"], "#text": "name:" } } |
| Comment Property Name (`commentPropName`) | text | If set to some property name, then comments are parsed from XML. E.g. for "$comment": <root><!-- mycomment --></root> -> { "root": { "$comment": "mycomment" } } |
| Ignore Attributes (`ignoreAttributes`) | toggle | Ignore attributes. By default, attributes are not ignored and have the "@" prefix. |
| Ignore Declaration (`ignoreDeclaration`) | toggle | Ignore declaration. E.g. for true, <?xml version="1.0"?><?elementnames <fred>, <bert>, <harry> ?><h1></h1> -> { "?elementnames": "", "h1": "" } |
| Ignore PI Tags (`ignorePiTags`) | toggle | Ignore PI tags. E.g. for true, <?xml version="1.0"?><?elementnames <fred>, <bert>, <harry> ?><h1></h1> -> { "h1": "" } |
| Always Array (`alwaysArray`) | text | Comma separated list of JSON paths to tags that will be always parsed as array. By default, single tags are parsed as objects. E.g. for "root.b", <root><b>foo</b></root> -> { "root": { "b": ["foo"] } } |
| Parse Number Leading Zeros (`numberParseLeadingZeros`) | toggle | When number with leading zeros like 08 should be parsed. 0.0 is not impacted. E.g. for true: "-06" -> -6, for false: "-06" -> "-06" |
| Parse Hex Numbers (`numberParseHex`) | toggle | Set to false to skip parsing hex numbers. E.g. for true: "0x2f" -> 47, for false: "0x2f" -> "0x2f" |
| Skip Parse Number RegExp (`numberParseSkipLike`) | text | Skip parsing numbers matching regular expression. E.g. for /+[0-9]{10}/: "+1212121212" -> "+1212121212", for false: "+1212121212" -> 1212121212 |
| Parse Attribute Value (`parseAttributeValue`) | toggle | Parse attributes value. E.g. for true, <root enabled=true></root> -> { "root": { "@enabled": true } }; false would give { "root": { "@enabled": "true" } } |
| Parse Tag Value (`parseTagValue`) | toggle | Parse tags value. E.g. for true, <root>33</root> -> { "root": 33 }; false would give { "root": "33" } |
| Preserve Order (`preserveOrder`) | toggle | Preserve order. |
| Process Entities (`processEntities`) | toggle | Process default and DOCTYPE entites. |
| Remove Namespace Prefix (`removeNSPrefix`) | toggle | Remove namespace string from tag and attribute names. |
| Stop Nodes (`stopNodes`) | text | Comma separated list of JSON paths to tags that will be skipped from processing. You can also mention a tag which should not be processed irrespective of their path by prefixing with "*.". E.g. for "root.a", "*.pre", <root><a>foo<c>bar</c></a><pre><b>baz</b></pre></root> -> { "root": { "a": ["foo", "<c>bar</c>"], "pre": "<b>baz</b>" } } |
| Text Node Name (`textNodeName`) | text | Text value of a tag is parsed to #text property by default. You can provide a different property name, e.g. "$text". |
| Trim Values (`trimValues`) | toggle | Remove surrounding whitespace from tag or attribute value. |
| Unpaired Tags (`unpairedTags`) | text | Unpaired Tags are the tags which don't have a matching closing tag. Eg <br> in HTML. Parse unpaired tags by providing their comma separated list. |

## Output ports

### Port `out`

| Field | Type | Description |
| --- | --- | --- |
| JSON (`json`) | object | - |

## Full metadata (component.json)

```json
{
  "name": "appmixer.utils.xml.XmlToJson",
  "author": "David Durman <david@client.io>",
  "description": "Convert XML to JSON.",
  "inPorts": [
    {
      "name": "in",
      "schema": {
        "type": "object",
        "properties": {
          "xml": {
            "type": "string"
          },
          "allowBooleanAttributes": {
            "type": "boolean"
          },
          "alwaysCreateTextNode": {
            "type": "boolean"
          },
          "attributesGroupName": {
            "type": "string"
          },
          "attributeNamePrefix": {
            "type": "string"
          },
          "cdataPropName": {
            "type": "string"
          },
          "commentPropName": {
            "type": "string"
          },
          "ignoreAttributes": {
            "type": "boolean"
          },
          "ignoreDeclaration": {
            "type": "boolean"
          },
          "ignorePiTags": {
            "type": "boolean"
          },
          "alwaysArray": {
            "type": "string"
          },
          "numberParseLeadingZeros": {
            "type": "boolean"
          },
          "numberParseHex": {
            "type": "boolean"
          },
          "numberParseSkipLike": {
            "type": "string"
          },
          "parseAttributeValue": {
            "type": "boolean"
          },
          "parseTagValue": {
            "type": "boolean"
          },
          "preserveOrder": {
            "type": "boolean"
          },
          "processEntities": {
            "type": "boolean"
          },
          "removeNSPrefix": {
            "type": "boolean"
          },
          "stopNodes": {
            "type": "string"
          },
          "textNodeName": {
            "type": "string"
          },
          "trimValues": {
            "type": "boolean"
          },
          "unpairedTags": {
            "type": "string"
          }
        }
      },
      "inspector": {
        "inputs": {
          "xml": {
            "type": "textarea",
            "label": "XML",
            "index": 1,
            "tooltip": "XML text content to convert to JSON."
          },
          "allowBooleanAttributes": {
            "type": "toggle",
            "label": "Allow Boolean Attributes",
            "defaultValue": false,
            "index": 2,
            "tooltip": "To allow attributes without value. &lt;root checked&gt;&lt;/root&gt; -> { \"root\": { \"@checked\": true } }"
          },
          "alwaysCreateTextNode": {
            "type": "toggle",
            "label": "Always Create Text Node",
            "defaultValue": false,
            "index": 3,
            "tooltip": "Instead of creating a property with the tag name and assign the value directly, create a #text node with the value. &lt;root&gt;foo&lt;/root&gt; -> { \"root\": { \"#text\": foo } }"
          },
          "attributesGroupName": {
            "type": "text",
            "label": "Attributes Group Name",
            "index": 4,
            "tooltip": "To group all the attributes of a tag under given property name. E.g. for \"_@\": &lt;root a=foo b=bar&gt;&lt;/root&gt; -> { \"root\": { \"_@\": { \"a\": \"foo\", \"b\": \"bar\" } } }"
          },
          "attributeNamePrefix": {
            "type": "text",
            "label": "Attribute Name Prefix",
            "defaultValue": "@",
            "index": 5,
            "tooltip": "To recognize attributes in JSON separately. E.g. for \"_@\": &lt;root a=foo&gt;&lt;a&gt;wow&lt;/a&gt;&lt;/root&gt; -> { \"root\": { \"a\": \"wow\", \"_@\": \"foo\" } }"
          },
          "cdataPropName": {
            "type": "text",
            "label": "CDATA Property Name",
            "index": 6,
            "tooltip": "If not set to some property name, then CDATA values are merged to tag's text value. E.g. for \"$cdata\": &lt;name&gt;name:&lt;![CDATA[&lt;some&gt;Jack&lt;/some&gt;]]&gt;&lt;![CDATA[Jack]]&gt;&lt;/name&gt; -> { \"name\": { \"$cdata\": [\"&lt;some&gt;Jack&lt;/some&gt;\", \"Jack\"], \"#text\": \"name:\" } }"
          },
          "commentPropName": {
            "type": "text",
            "label": "Comment Property Name",
            "index": 7,
            "tooltip": "If set to some property name, then comments are parsed from XML. E.g. for \"$comment\": &lt;root&gt;&lt;!-- mycomment --&gt;&lt;/root&gt; -> { \"root\": { \"$comment\": \"mycomment\" } }"
          },
          "ignoreAttributes": {
            "type": "toggle",
            "label": "Ignore Attributes",
            "defaultValue": false,
            "index": 8,
            "tooltip": "Ignore attributes. By default, attributes are not ignored and have the \"@\" prefix."
          },
          "ignoreDeclaration": {
            "type": "toggle",
            "label": "Ignore Declaration",
            "defaultValue": false,
            "index": 9,
            "tooltip": "Ignore declaration. E.g. for true, &lt;?xml version=\"1.0\"?&gt;&lt;?elementnames &lt;fred&gt;, &lt;bert&gt;, &lt;harry&gt; ?&gt;&lt;h1&gt;&lt;/h1&gt; -> { \"?elementnames\": \"\", \"h1\": \"\" }"
          },
          "ignorePiTags": {
            "type": "toggle",
            "label": "Ignore PI Tags",
            "defaultValue": true,
            "index": 10,
            "tooltip": "Ignore PI tags. E.g. for true, &lt;?xml version=\"1.0\"?&gt;&lt;?elementnames &lt;fred&gt;, &lt;bert&gt;, &lt;harry&gt; ?&gt;&lt;h1&gt;&lt;/h1&gt; -> { \"h1\": \"\" }"
          },
          "alwaysArray": {
            "type": "text",
            "label": "Always Array",
            "index": 11,
            "tooltip": "Comma separated list of JSON paths to tags that will be always parsed as array. By default, single tags are parsed as objects. E.g. for \"root.b\", &lt;root&gt;&lt;b&gt;foo&lt;/b&gt;&lt;/root&gt; -> { \"root\": { \"b\": [\"foo\"] } }"
          },
          "numberParseLeadingZeros": {
            "type": "toggle",
            "label": "Parse Number Leading Zeros",
            "defaultValue": true,
            "index": 12,
            "tooltip": "When number with leading zeros like 08 should be parsed. 0.0 is not impacted. E.g. for true: \"-06\" -> -6, for false: \"-06\" -> \"-06\""
          },
          "numberParseHex": {
            "type": "toggle",
            "label": "Parse Hex Numbers",
            "defaultValue": true,
            "index": 13,
            "tooltip": "Set to false to skip parsing hex numbers. E.g. for true: \"0x2f\" -> 47, for false: \"0x2f\" -> \"0x2f\""
          },
          "numberParseSkipLike": {
            "type": "text",
            "label": "Skip Parse Number RegExp",
            "index": 14,
            "tooltip": "Skip parsing numbers matching regular expression. E.g. for /+[0-9]{10}/: \"+1212121212\" -> \"+1212121212\", for false: \"+1212121212\" -> 1212121212"
          },
          "parseAttributeValue": {
            "type": "toggle",
            "label": "Parse Attribute Value",
            "defaultValue": true,
            "index": 15,
            "tooltip": "Parse attributes value. E.g. for true, &lt;root enabled=true&gt;&lt;/root&gt; -> { \"root\": { \"@enabled\": true } }; false would give { \"root\": { \"@enabled\": \"true\" } }"
          },
          "parseTagValue": {
            "type": "toggle",
            "label": "Parse Tag Value",
            "defaultValue": true,
            "index": 16,
            "tooltip": "Parse tags value. E.g. for true, &lt;root&gt;33&lt;/root&gt; -> { \"root\": 33 }; false would give { \"root\": \"33\" }"
          },
          "preserveOrder": {
            "type": "toggle",
            "label": "Preserve Order",
            "defaultValue": false,
            "index": 17,
            "tooltip": "Preserve order."
          },
          "processEntities": {
            "type": "toggle",
            "label": "Process Entities",
            "defaultValue": true,
            "index": 18,
            "tooltip": "Process default and DOCTYPE entites."
          },
          "removeNSPrefix": {
            "type": "toggle",
            "label": "Remove Namespace Prefix",
            "defaultValue": false,
            "index": 19,
            "tooltip": "Remove namespace string from tag and attribute names."
          },
          "stopNodes": {
            "type": "text",
            "label": "Stop Nodes",
            "index": 20,
            "tooltip": "Comma separated list of JSON paths to tags that will be skipped from processing. You can also mention a tag which should not be processed irrespective of their path by prefixing with \"*.\". E.g. for \"root.a\", \"*.pre\", &lt;root&gt;&lt;a&gt;foo&lt;c&gt;bar&lt;/c&gt;&lt;/a&gt;&lt;pre&gt;&lt;b&gt;baz&lt;/b&gt;&lt;/pre&gt;&lt;/root&gt; -> { \"root\": { \"a\": [\"foo\", \"&lt;c&gt;bar&lt;/c&gt;\"], \"pre\": \"&lt;b&gt;baz&lt;/b&gt;\" } }"
          },
          "textNodeName": {
            "type": "text",
            "label": "Text Node Name",
            "index": 21,
            "tooltip": "Text value of a tag is parsed to #text property by default. You can provide a different property name, e.g. \"$text\"."
          },
          "trimValues": {
            "type": "toggle",
            "label": "Trim Values",
            "defaultValue": true,
            "index": 22,
            "tooltip": "Remove surrounding whitespace from tag or attribute value."
          },
          "unpairedTags": {
            "type": "text",
            "label": "Unpaired Tags",
            "index": 23,
            "tooltip": "Unpaired Tags are the tags which don't have a matching closing tag. Eg &lt;br&gt; in HTML. Parse unpaired tags by providing their comma separated list."
          }
        }
      }
    }
  ],
  "outPorts": [
    {
      "name": "out",
      "options": [
        {
          "label": "JSON",
          "value": "json",
          "schema": {
            "type": "object",
            "example": {
              "note": {
                "to": "Jane Doe",
                "body": "Meeting at 10am"
              }
            }
          }
        }
      ]
    }
  ],
  "icon": "(data URI omitted)"
}
```
