XML ↔ JSON / TOML / INI API

Convert XML to JSON and back, check XML well-formedness with line and column, pretty-print or minify XML, and convert TOML or INI to and from JSON.

POSThttps://apibox.io.vn/v1/xml-convert

Send a document in xml, json, toml or ini (or as the raw body with from) and pick to: json, xml, toml, ini, validate, pretty or minify. XML to JSON keeps attributes under a prefix (@_ by default, attribute_prefix=none for none), puts mixed text in #text, and can force arrays for repeated elements (array_tags=item,line or always_array=true), keep the element order (preserve_order=true), strip namespace prefixes (remove_ns=true) and keep CDATA or comments. Values stay strings unless parse_values=true, so tax codes and invoice numbers such as 0101234567 keep their leading zeros.

JSON to XML turns keys starting with the prefix into attributes, arrays into repeated elements and wraps the result in root when needed; the output is checked again and a warning is returned if a key is not a valid element name. validate reports the first error with its line and column, plus the root element, namespaces and element count; pretty / minify re-indent XML (or JSON) keeping comments, CDATA and processing instructions.

Safety: entity expansion is limited (no "billion laughs"), external entities (SYSTEM / PUBLIC) are never loaded, nesting is capped at 256 levels and documents at 5 MB. TOML support covers TOML 1.0 except arbitrary-precision integers (dates and times become strings, inf / nan become strings); INI supports sections, ; / # comments, quoted values, key[] arrays and optional dotted sections.

Parameters

NameInTypeRequiredDefault
xmlbodystringnoXML document (or send json, toml, ini, input + from, or the raw body).
jsonbodyobjectnoJSON value (object or JSON string) to convert.
tomlbodystringnoTOML document.
inibodystringnoINI document.
frombodystringnoxml, json, toml or ini (detected when omitted).
tobodystringnojsonjson, xml, toml, ini, validate, pretty or minify (default json, or xml for JSON input).
attribute_prefixbodystringno@_Prefix of attribute keys; none for no prefix.
attributesbodybooleannotruefalse drops attributes.
text_node_namebodystringno#textKey of the text of elements that also have attributes or children.
array_tagsbodystringnoComma-separated element names always returned as arrays.
always_arraybodybooleannofalseEvery element below the root becomes an array.
parse_valuesbodybooleannofalseConvert numbers and booleans (XML, INI). Leading zeros are kept as strings.
preserve_orderbodybooleannofalseOrdered array output (exact element order, mixed content).
remove_nsbodybooleannofalseRemove namespace prefixes (inv:Total → Total).
keep_cdatabodybooleannofalseKeep CDATA sections under #cdata.
keep_commentsbodybooleannofalseKeep comments under #comment.
rootbodystringnorootJSON to XML: name of the wrapping root element.
indentbodynumberno2Indentation for XML / JSON output (0 = one line).
declarationbodybooleannotrueJSON to XML: add <?xml version="1.0" encoding="UTF-8"?>.
nested_sectionsbodybooleannofalseINI: [a.b] becomes nested objects.

Example

curl -X POST "https://apibox.io.vn/v1/xml-convert" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"xml":"<invoice id=\"HD001\"><buyer>Công ty A</buyer><item><name>Pen</name><qty>2</qty></item><item><name>Book</name><qty>1</qty></item></invoice>"}'

Response

{
  "from": "xml",
  "to": "json",
  "root": "invoice",
  "json": {
    "invoice": {
      "buyer": "Công ty A",
      "item": [
        {
          "name": "Pen",
          "qty": "2"
        },
        {
          "name": "Book",
          "qty": "1"
        }
      ],
      "@_id": "HD001"
    }
  }
}

Use cases

  • Read e-invoice, tax return or social-insurance XML files as JSON
  • Send JSON data to a legacy SOAP / XML system
  • Validate XML uploaded by users and show the exact error line
  • Convert config files between TOML, INI and JSON

FAQ

Why are numbers returned as strings?

XML has no types, and codes like 0101234567 must keep their leading zeros. Add parse_values=true to get numbers and booleans.

How do I always get an array for repeated elements?

List them in array_tags (e.g. array_tags=HHDVu), or use always_array=true for every element below the root.

Is DOCTYPE / entity processing safe?

Yes: internal entities are expanded only within small limits, nested expansions beyond them stay as text, and external entities are rejected.

Related APIs

Start with 1,000 free requests every month. Get free API key →