XML To TypeScript POJO Generator
Convert XML data into TypeScript interface definitions instantly in your browser.
Generate ready-to-use TypeScript interface definitions from arbitrary XML payloads without leaving your browser. Paste a sample document, tweak the preferred root interface identifier, and copy the resulting types straight into your codebase.
Why convert XML to TypeScript interfaces?
- Stronger compile-time guarantees: Replace loose
anyshapes with explicit interface contracts when consuming SOAP, RSS, or configuration XML feeds. - Faster IDE autocompletion: Editors surface property names and nested object hints once the model is statically typed.
- Cleaner refactors: Renaming a field in TypeScript propagates safely across consumers instead of surfacing as runtime exceptions.
- Quick prototyping: Spin up new clients against unfamiliar XML APIs with zero hand-rolled boilerplate.
How the conversion works
The tool first parses your XML using fast-xml-parser, normalises attributes (prefixed with @_) and merges repeated sibling elements into arrays. The resulting plain object is then fed into json-to-ts, which infers interface declarations from observed shapes. Optional unions appear automatically when sibling items diverge.
Tips for higher-quality output
- Provide a representative sample with all optional fields populated for better type coverage.
- Use a meaningful root interface name (PascalCase) so generated child interfaces inherit clean prefixes.
- Strip irrelevant SOAP envelope wrappers if you only need the inner payload typed.
Frequently Asked Questions
Does the XML payload ever leave my browser?
No. Parsing and inference happen entirely client-side with JavaScript, so your XML data never leaves your device.
How are XML attributes represented?
Attributes appear as regular interface properties alongside element children. The internal @_ prefix used by the parser is stripped automatically before generating types.
Why are some primitives typed as string instead of number or boolean?
XML is text based. The parser attempts to coerce numeric and boolean literals, but ambiguous values stay as strings to avoid silently changing semantics.
Will repeated sibling elements become arrays?
Yes. When the parser detects two or more siblings with identical tag names, they are merged into an array and the inferred interface uses the structure of the first item.
Can I download the generated interfaces?
Yes. Use the download button above the output editor to save the result as a types.ts file ready to drop into your project.
Related tools
Your recent visits