JSON ↔ XML Converter

Convert JSON to XML and back - best-effort, with a documented convention

0 chars · 0 lines
0 chars

Conversion convention

JSON → XML

  • The document is wrapped in a <root> element
  • Arrays become repeated sibling elements, one per item
  • Keys that are invalid XML names are sanitized (spaces and special characters become underscores)
  • Null becomes an empty element

XML → JSON

  • Attributes become @_name keys
  • Elements with only text become plain values (numbers, booleans and null are detected)
  • Elements with mixed text and children use a #text key
  • Repeated sibling elements become an array