Convert XML to JSON by Example
XML is still everywhere: RSS feeds, SOAP-style APIs, Maven POM files, Android manifests, government feeds, legacy enterprise exports, and HTML-like fragments from scraping workflows.
A normal XML-to-JSON converter changes syntax. Latentmachine can do that, but the useful part is teaching a transformation at the same time. You paste XML input, show the JSON shape you want, and Latentmachine infers a deterministic rule you can inspect.
Example: XML to JSON
<order id="o1">
<customer>Ana</customer>
<total>119.50</total>
<status>paid</status>
</order>
Show the output you need:
{
"order_id": "o1",
"customer": "Ana",
"total": 119.5,
"paid": true
}
Latentmachine parses the XML into structured data, compares it with the output, and learns the rule: copy the id attribute, copy the customer, coerce the total to a number, and map the status to a boolean.
XML Mapping Convention
XML has concepts JSON does not, so Latentmachine uses a predictable convention:
- Attributes become
@keys, such as@id. - Elements with only text become strings.
- Repeated sibling elements become arrays.
- Text mixed with child elements is stored as
#text. - CDATA becomes plain text.
- Self-closing elements become
null. - Namespace prefixes are stripped by default.
XML text values stay strings when parsed. If you need numbers or booleans, show that in your output example and the engine infers the conversion.
More Than Syntax Conversion
You can convert XML to JSON, but also reshape it:
- Flatten Maven POM metadata into a deployment record.
- Extract RSS feed items into CSV rows.
- Turn XML attributes into normal API fields.
- Convert SOAP-like response payloads into smaller JSON objects.
- Generate XML from JSON when another system needs XML output.
If the examples are ambiguous, Latentmachine tells you what extra example would prove the rule instead of silently guessing.
Exports
For XML rules marked safe, Latentmachine can copy or download the transformed output and export JavaScript, n8n code, Make.com code, or a plain JavaScript function.
Standalone CLI export is intentionally not enabled for XML yet because it would need to inline the XML parser into every generated file. JSON, CSV, TOML, and .env rules already support standalone CLI export.
Check a batch →Related
Use Latentmachine as an MCP Server for Claude and Cursor
Connect Latentmachine to Claude Desktop, Claude Code, or Cursor as an MCP server. The AI does the data transformation, then calls a deterministic engine to verify whether every row is consistent. Setup takes one line.
Verify AI Data Transformations in Node.js
Use @latentmachine/verify to check whether AI-generated data transformations are consistent, infer deterministic rules from examples, and apply them to new data. Zero dependencies. Works in any Node.js pipeline, CI job, or automation script.
Audit a CSV Migration With One Paste
Before importing migrated CSV records, verify that every row followed the same transformation rule. Paste original and transformed data into Latentmachine Verify to catch inconsistent rows.